选择器:移除事件不存在
你好@Justin8303“selector:remove”指的是全局选择器的容器,所以只有当选择器实际从全局集合中移除时才触发,而不是从组件中移除。当你从组件中移除选择器时,它依然存在,因为它可能也被用在其他地方。 如果你需要跟踪组件类的变化,我建议使用“component:update:classes”事件
阅读下方完整回答 ↓问题
葡萄JS版本
- 我确认使用最新版本的GrapesJS
你用的是什么浏览器?
铬101
可复制演示链接
https://jsfiddle.net/sdrf72wx/1/
描述一下那个虫子
如何复现这个漏洞?
- 在编辑器初始化时执行以下代码
- 添加和移除组件的选择器
- 查看控制台输出
预期的行为是什么? 如果组件选择器被移除,它应该会把选择器打印到控制台。
目前的行为是什么? 如果选择器被移除,控制台不会提示,因此“selector:remove”事件不会触发。 此外,“selector”事件只捕获“selector:add”和“selector:update”,但不捕获“selector:remove”,但在选择器管理器的[event](https://grapesjs.com/docs/api/selector_manager.html#available-events)中它们可用。
如果需要执行某些代码来复现该漏洞,请粘贴到下面: “''js editor.on(“selector:remove”, (data) => { console.log(数据) })
### 行为准则
- [x] 我同意遵守本项目的行为准则
回答(2)
你好@Justin8303“selector:remove”指的是全局选择器的容器,所以只有当选择器实际从全局集合中移除时才触发,而不是从组件中移除。当你从组件中移除选择器时,它依然存在,因为它可能也被用在其他地方。 如果你需要跟踪组件类的变化,我建议使用“component:update:classes”事件
谢谢你举报,@Justin8303。 关于selector:remove event不存在的好问题。推荐的组件方法是使用事件驱动的API。 从这里开始: 查看你所在模块的[GrapesJS文档](https://grapesjs.com/docs/) 寻找“on()”事件监听器方法 大多数操作可以通过监听编辑器和组件事件来实现 常见模式: “JavaScript 留意变化 editor.on('change', () => console.log('something changed')); 组件生命周期 editor.on('component:mount', (c) => console...
相关问答
通过相似的问题讨论继续研究。
问题 #5460
从“pageManager”加载“组件”和“样式”
葡萄JS版本[X] 我确认使用最新版本的GrapesJS你用的是什么浏览器? Chrome v117.0.5938.149可复制演示链接 https://jsfiddle.net/9oLrsvya/描述一下那个虫子 如何复现这个漏洞?请参见 jsfiddle 中的“pageMa...
问题 #5316
编辑者未订阅选择器:移除
葡萄JS版本[X] 我确认使用最新版本的GrapesJS你用的是什么浏览器? Chrome v115.0.5790.170可复制演示链接 https://jsfiddle.net/BenKhz/yfwqc6mu/1/ 参考[这里的文档](https://grapesjs.com...
问题 #3289
(0.16.41) 组件已失去其风格
版本: 0.16.41 你能重现演示中的bug吗? [X] 是的 [ ] 不 预期的行为是什么? 1)将选中的父组件(容器)复制到剪贴板。 2)从剪贴板中选定的父组件(容器)粘贴到同一页面或其他页面。 3)所有组件都保留ID样式和内联样式。 目前的行为是什么? 1)将选中的父组...
问题 #3235
“component:update”在组件移动时不会触发
摘自 https://github.com/artf/grapesjs/blob/dev/src/editor/index.js#L33'component:update' - 当组件被更新(移动、样式等)时触发,模型作为参数传递给回调 重现这个bug使用“move”API 移...
与此问题匹配的付费插件
根据问题关键词和标签相关性精选,助你更快交付。
正在加载付费插件推荐……
相关教程
关于同一主题的深入指南。
教程
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.
浏览插件分类
直接跳转到市场上的插件分类页面。