grapesjs如何实现自定义组件,内容通过ajax从后台获取,更改属性式重新渲染?
比如自定义一个推荐文章列表,可以选择文章的数量与排列方式,当属性更改时,渲染代码也会发生变化。
网友回复
主要是editor.DomComponents.addType自定义一个组件,然后在组件init的时候,调用fetch从后端url获取数据,然后再调用 model.set('content', data.content);与model.components(data.content)更新组件内容,示例代码如下:
const editor = grapesjs.init({
container: '#gjs',
fromElement: true,
height: '100%',
width: 'auto',
plugins: ['gjs-preset-webpage'],
storageManager: false,
blockManager: {
blocks: [
{
id: 'form-new',
label: '<b>Form New</b>',
attributes: { class: 'gjs-block-form-new' },
content: {
type: 'form-new',
...点击查看剩余70%


