如何在预览模式下让组件不可编辑?
通过这种方式修复你的功能 “''js whenRunPreview(ed, type) { ed.getWrapper().findType(type).forEach(cmp => cmp.set({ editable: false })) } ```
阅读下方完整回答 ↓问题
我正在尝试让预览模式下的组件无法编辑。以下代码无法正常工作。请帮我解决这个问题。
编辑; ngOnInit(){ this.editor = this.initializeEditor(); this.editor.on('load', () => this.editor.runCommand('preview')); this.editor.on('run:preview', () => { this.editor.Panels.getPanels().reset([ 某种代码 ]) this.whenRunPreview(this.editor,'text'); this.whenRunPreview(this.editor,'image'); ..... }
whenRunPreview(editor, compType) { editor.on('run:preview', () => { 编辑。DomComponents.getWrapper().onAll( (comp) => comp.is(compType) && comp.set({ editable: false }) ); });
回答(2)
通过这种方式修复你的功能 “''js whenRunPreview(ed, type) { ed.getWrapper().findType(type).forEach(cmp => cmp.set({ editable: false })) }
谢谢你举报,@niveth09。 关于如何让组件在预览模式下不可编辑?的好问题。推荐的组件方法是使用事件驱动的API。 从这里开始: 查看你所在模块的[GrapesJS文档](https://grapesjs.com/docs/) 寻找“on()”事件监听器方法 大多数操作可以通过监听编辑器和组件事件来实现 常见模式: “JavaScript 留意变化 editor.on('change', () => console.log('something changed')); 组件生命周期 editor.on('component:mount', (c) => console.log('comp...
相关问答
通过相似的问题讨论继续研究。
问题 #5019
使用 loadProjectData() 时无法在编辑器初始化时设置预览模式
葡萄JS版本 [X] 我确认使用最新版本的GrapesJS 你用的是什么浏览器? Chrome v111 可复制演示链接 https://codesandbox.io/s/grapesjs-react-components-forked-h3j496?file=/src/ind...
问题 #5346
删除组件而不删除其对应样式
葡萄JS版本 [X] 我确认使用最新版本的GrapesJS 你用的是什么浏览器? 最新版本的Chrome浏览器 可复制演示链接 https://grapesjs.com/demo.html 描述一下那个虫子 如何复现这个漏洞? <img width=“1665” alt=“im...
问题 #6409
手机上无法拖动移动组件
葡萄JS版本 [x] 我确认使用最新版本的GrapesJS 你用的是什么浏览器? Chrome v133 可复制演示链接 https://jsfiddle.net/2hjdrb7L/1/ 描述一下那个虫子 如何复现这个漏洞? 用grapesjs v0.22.x和grapesjs...
问题 #4837
HTML元素的ID会在projectData加载的不同页面上递增
葡萄JS版本 [X] 我确认使用最新版本的GrapesJS 你用的是什么浏览器? Firefox 109 可复制演示链接 https://grapesjs.com/demo.html 描述一下那个虫子 你好, 我注意到当我在 projectData 中加载多个 HTML 中使用...
与此问题匹配的付费插件
根据问题关键词和标签相关性精选,助你更快交付。
正在加载付费插件推荐……
相关教程
关于同一主题的深入指南。
教程
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.
浏览插件分类
直接跳转到市场上的插件分类页面。