问问题
1107 次
1 回答
2
更新
我认为在这种情况下,您可以挂钩component
诸如添加、更新、删除之类的事件来更新您的文本区域。
在下面的示例中,我正在这样做Codepen
const editor = grapesjs.init({
height: '100%',
container: '#gjs',
showOffsets: true,
fromElement: true,
noticeOnUnload: false,
storageManager: false,
plugins: ['grapesjs-preset-webpage'],
});
const htmlTextarea = document.getElementById('html')
const cssTextarea = document.getElementById('css')
const updateTextarea = (component, editor)=>{
const e = component.em.get("Editor");
htmlTextarea.value= e.getHtml();
cssTextarea.value= e.getCss();
}
editor.on('component:add', updateTextarea);
editor.on('component:update', updateTextarea);
editor.on('component:remove', updateTextarea);
const updateInstance = () => {
editor.setComponents(htmlTextarea.value)
editor.setStyle(cssTextarea.value)
}
document.getElementById('save').onclick=updateInstance;
于 2020-05-12T04:57:27.937 回答