如何保存GrapesJS编辑器的当前阶段



我使用GrapesJS创建了一个无代码工具。关闭工具后,内容会被刷新,我以前存储的内容也不见了。即使在关闭工具后,我也希望保留旧内容。我该如何实现?

您可以通过grapesjs存储管理器保存编辑器更改

这个存储管理器可以将您的更改保存在浏览器本地存储中,也可以远程保存到您的数据库中。

以下代码将保存到浏览器本地存储中。

const editor = grapesjs.init({
...
// Default configurations
storageManager: {
type: 'local', // Storage type. Available: local | remote
autosave: true, // Store data automatically
autoload: true, // Autoload stored data on init
stepsBeforeSave: 1, // If autosave is enabled, indicates how many changes are necessary before the store method is triggered
// ...
// Default storage options
options: {
local: {/* ... */},
remote: {/* ... */},
}
},
});

有关详细信息,请参阅https://grapesjs.com/docs/modules/Storage.html#configuration

最新更新