在程序中设置文本内容会在画布中清除
试试用“.getEl”方法在组件上,然后直接设置元素。 “''js const editor = Grapesjs.init({ 容器:“#gjs”, fromElement: 1, 身高:“100%”, storageManager: { type: 0 }, 插件:['GJS-Blocks-BASIC'] }); setTimeout(() => { const component = editor.getWrapper().find('.test-text')[0] const el = component.getEl(); el.textContent = “测试” }, 1000) ```
阅读下方完整回答 ↓问题
葡萄JS版本
- 我确认使用最新版本的GrapesJS
你用的是什么浏览器?
V126
可复制演示链接
https://jsfiddle.net/r5062suy/1/
描述一下那个虫子
如何复现这个漏洞?
- 运行演示链接(https://jsfiddle.net/r5062suy/1/)
- 我尝试通过 'editor.getWrapper().find('.test-text')[0].set('content', 'test')' 将 div 中的文本从“Hello world!!” 更新为“test”。
- 但它实际上是清除文本。
预期的行为是什么? 它会正确更新文本内容。
目前的行为是什么? 而是把它清理干净。
行为准则
- 我同意遵守本项目的行为准则
回答(4)
试试用“.getEl”方法在组件上,然后直接设置元素。 “''js const editor = Grapesjs.init({ 容器:“#gjs”, fromElement: 1, 身高:“100%”, storageManager: { type: 0 }, 插件:['GJS-Blocks-BASIC'] }); setTimeout(() => { const component = editor.getWrapper().find('.test-text')[0] const el = component.getEl(); el.textContent = “测试” }, 1000)...
“''jsconst component = editor.getWrapper().find('.test-text')[0]const el = component.getEl();el.textContent = “测试”
@mannyyang你是从哪里找到“set('content', ...')的用法的?它更像是私人财产,你绝不应该使用它。
要程序化地更新内部组件,请使用 'component.components('test')'
谢谢你举报,@mannyyang。 关于设置文本内容程序化后,画布中会清除,这个问题很棒。GrapesJS 推荐的方法是使用事件驱动 API。 从这里开始: 查看你所在模块的[GrapesJS文档](https://grapesjs.com/docs/) 寻找“on()”事件监听器方法 大多数操作可以通过监听编辑器和组件事件来实现 常见模式: “JavaScript 留意变化 editor.on('change', () => console.log('something changed')); 组件生命周期 editor.on('component:mount', (c) => conso...
相关问答
通过相似的问题讨论继续研究。
问题 #5633
无法在“component:remove”处理程序中选择组件
葡萄JS版本 [X] 我确认使用最新版本的GrapesJS 你用的是什么浏览器? Chrome 版本 120.0.6099.225 可复制演示链接 https://jsfiddle.net/wattnu/opmwfvjn/ 描述一下那个虫子 如何复现这个漏洞?打开并拉动小提琴画...
问题 #5086
Style:property:update 和 Property onChange 都被过度触发
葡萄JS版本 [X] 我确认使用最新版本的GrapesJS 你用的是什么浏览器? Chrome 版本 112.0.5615.137(官方版本) 可复制演示链接 https://jsfiddle.net/SagarMaria/sunygp2f/3/ 描述一下那个虫子 如何复现这个...
问题 #4323
当你在Canvas上有2k组件时,拖拽组件到画布时出现性能问题
葡萄JS版本[X] 我确认使用最新版本的GrapesJS你用的是什么浏览器? Google Chrome 版本 101.0.4951.41(官方版本)(64 位)可复制演示链接 https://jsfiddle.net/Laze0pyg/描述一下那个虫子 如何复现这个漏洞?使用...
问题 #4497
从 v18.4 更新到 GrapesJS v19.5 会导致 Chrome 变得无响应
葡萄JS版本[x] 我确认使用最新版本的GrapesJS你用的是什么浏览器? Chrome 104.0.5112.79可复制演示链接 https://jsfiddle.net/gvrnw2c3/4/描述一下那个虫子 如何复现这个漏洞? 我目前无法用 jsfiddle 重现这个...
与此问题匹配的付费插件
根据问题关键词和标签相关性精选,助你更快交付。
正在加载付费插件推荐……
相关教程
关于同一主题的深入指南。
教程
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.
浏览插件分类
直接跳转到市场上的插件分类页面。