[紧急!! 问题:如何在 reactjs 项目中实现 LocalStorage??
本地storageManager会帮你完成所有工作,所以你不需要做现在那些手动操作。所以保留storageManager选项,把剩下的都删掉。 附言:使用useEffect要小心,添加一个空数组作为依赖,否则它会在每次渲染时调用初始化......
阅读下方完整回答 ↓问题
我正在尝试在 Reactjs 应用中实现 localstorage,但不知为何它没有在 localstorage 中存储数据 “JavaScript useEffect(() => { const templateComponent = JSON.parse( localStorage.getItem(“gjs-components”) ); console.log(模板组件); const templateStyle = JSON.parse(localStorage.getItem(“gjs-style”)); console.log(模板样式); const editor = Grapesjs.init({ 容器:“#editor”, 宽度:“100VW”, 高度:“100VH”, styleManager: { clearProperties: true, }, components: JSON.parse(localStorage.getItem(“gjs-components”)), style: JSON.parse(localStorage.getItem(“gjs-style”)), storageManager: { 编号:“GJS-”, 类型:“本地”, 自动保存:正确, 自动加载:正确, stepsBeforeSave: 1, }, }); ```
回答(2)
本地storageManager会帮你完成所有工作,所以你不需要做现在那些手动操作。所以保留storageManager选项,把剩下的都删掉。
附言:使用useEffect要小心,添加一个空数组作为依赖,否则它会在每次渲染时调用初始化......
谢谢你举报,@sanchit36。 关于[紧急!!的好问题 问题:如何在 reactjs 项目中实现 LocalStorage??.推荐的 StyleManager 方法是使用事件驱动的 API。 从这里开始: 查看你所在模块的[GrapesJS文档](https://grapesjs.com/docs/) 寻找“on()”事件监听器方法 大多数操作可以通过监听编辑器和组件事件来实现 常见模式: “JavaScript 留意变化 editor.on('change', () => console.log('something changed')); 组件生命周期 editor.on('com...
相关问答
通过相似的问题讨论继续研究。
问题 #3137
当我选择某个特定元素时,我没有看到它的样式。这个问题只发生在某些元素上。
未获得所选元素的样式 这是我的代码, const model = 编辑器。StyleManager.getModelToStyle(component); let styleObject = model.getStyle(); console.log(“样式”,styleObj...
问题 #3627
:我正在尝试复制页面,但由于 ID,样式无法应用,结尾的 -2,-3 发生了变化。
“JavaScript const duplicatePage = (编辑者) => { let components = editor.getHtml(); 令 css = editor.getCss(); 让newPage = 编辑器。Pages.add({ 样式:CSS,...
问题 #4900
SetStyle/getCss() 生成重复的 CSS
葡萄JS版本[X] 我确认使用最新版本的GrapesJS你用的是什么浏览器? Chrome 最新动态可复制演示链接 https://codesandbox.io/s/silent-river-ifczcv描述一下那个虫子 如何复现这个漏洞?访问网站参见控制台。注意“”和“bod...
问题 #3225
如何从复选框特性中更新风格?
你好@artf 我尝试用复选框特性更新样式,但它没有调用函数。 这是代码 非常感谢你能提供的任何见解! 谢谢
与此问题匹配的付费插件
根据问题关键词和标签相关性精选,助你更快交付。
正在加载付费插件推荐……
相关教程
关于同一主题的深入指南。
教程
GrapesJS DevTools: A Developer Panel Inside Your Editor
If you've ever debugged GrapesJS with console.log(editor.getSelected()) and a dozen throwaway event listeners — this post is for you.
教程
How to Build a Production GrapesJS Editor: The Complete Walkthrough of Brief, Preset, Plugins, and Services
A complete walkthrough of building a production GrapesJS editor: how to choose a preset, pick plugins, and scope setup services without burning a sprint.
教程
Big Updates: TinyMCE 8 and Placeholder 2.0 for GrapesJS
In May we shipped major updates to two of our most popular GrapesJS plugins — TinyMCE Inline Text Editor and Placeholder.
浏览插件分类
直接跳转到市场上的插件分类页面。