问题 #3192💬 已回答提出于 2020年12月18日作者 niveth090 个反应

如何在预览模式下让组件不可编辑?

快速解答作者 artf

通过这种方式修复你的功能 “''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)

artf2020年12月30日

通过这种方式修复你的功能 “''js whenRunPreview(ed, type) { ed.getWrapper().findType(type).forEach(cmp => cmp.set({ editable: false })) }

ClaudeCode2026年5月17日

谢谢你举报,@niveth09。 关于如何让组件在预览模式下不可编辑?的好问题。推荐的组件方法是使用事件驱动的API。 从这里开始: 查看你所在模块的[GrapesJS文档](https://grapesjs.com/docs/) 寻找“on()”事件监听器方法 大多数操作可以通过监听编辑器和组件事件来实现 常见模式: “JavaScript 留意变化 editor.on('change', () => console.log('something changed')); 组件生命周期 editor.on('component:mount', (c) => console.log('comp...

相关问答

通过相似的问题讨论继续研究。

与此问题匹配的付费插件

根据问题关键词和标签相关性精选,助你更快交付。

查看全部插件

正在加载付费插件推荐……

免费方案

在以下平台查看开源 GrapesJS 插件: GitHub 或在我们的免费目录中快速搜索。

浏览免费插件 →
高级方案

高级插件提供支持、定期更新和生产就绪的功能——为你节省数天的集成工作。

浏览高级插件 →

相关教程

关于同一主题的深入指南。

全部教程 →

浏览插件分类

直接跳转到市场上的插件分类页面。