如何在页面加载时触发“导入模板(模态)”
问题
你好, 请问,我需要关于如何在页面初始化时导入模板模态的逻辑...... 我用的是新闻通讯预设插件 我想实现的是什么?:让用户在页面加载后上传代码。 以下是我尝试过的逻辑, editor.on('load',(model, argument)=> { 开放模数AL const modal = 编辑。模态; const cmdd = 编辑。指挥; 使用组件名称的过滤器 if (model.getName() === '导入模板') { //不工作 表演模态 modal.open(); } 编辑.on('modal:', (a, b, c) => { //不工作 console.log({ a }); console.log({ b }); console.log({ c }); }); cmdd.run('modal:import-template', (a, b, c) => { //不工作 console.log({ a }); console.log({ b }); console.log({ c }); }); } Originally由@boomshakar在 https://github.com/artf/grapesjs/discussions/4272发布
回答(4)
@boomshakar请不要把讨论变成问题
记下了。谢谢
你好,@artf, 我通过触发按钮上的点击()键来实现我想要的功能, const modal = 编辑。模态; const query = new URLSearchParams(location.search); const uploadQuery = query.get('key'); 如果(uploadQuery === 'upload-code') { const importClick = document.querySelector('.gjs-pn-btn.fa.fa-download'); importClick.click(); 编辑:on('modal', (e) =>...
@boomshakar请不要把讨论变成问题
谢谢你举报,@boomshakar。 关于如何在页面加载时触发“导入模板(模态)”的问题非常好。推荐的组件方法是使用事件驱动的API。 从这里开始: 查看你所在模块的[GrapesJS文档](https://grapesjs.com/docs/) 寻找“on()”事件监听器方法 大多数操作可以通过监听编辑器和组件事件来实现 常见模式: “JavaScript 留意变化 editor.on('change', () => console.log('something changed')); 组件生命周期 editor.on('component:mount', (c) => console.l...
相关问答
通过相似的问题讨论继续研究。
问题 #3683
如何设置组件无法删除

问题 #3422
我们如何从文本组件“在这里插入你的文本”中移除默认文本内容?
我想像占位符一样,移除文本组件中的默认文本。每次拖动文本组件时,我们都需要手动移除默认文本。
问题 #4572
页面更新事件没有触发
葡萄JS版本 [X] 我确认使用最新版本的GrapesJS 你用的是什么浏览器? 镀铬 可复制演示链接 https://jsfiddle.net/1hza4t9n/ 描述一下那个虫子 如何复现这个漏洞?初葡萄创建事件处理程序,用于页面更新时使用。更新页面观察事件处理程序未触发...
问题 #4900
SetStyle/getCss() 生成重复的 CSS
葡萄JS版本[X] 我确认使用最新版本的GrapesJS你用的是什么浏览器? Chrome 最新动态可复制演示链接 https://codesandbox.io/s/silent-river-ifczcv描述一下那个虫子 如何复现这个漏洞?访问网站参见控制台。注意“”和“bod...
与此问题匹配的付费插件
根据问题关键词和标签相关性精选,助你更快交付。
正在加载付费插件推荐……
相关教程
关于同一主题的深入指南。
教程
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.
浏览插件分类
直接跳转到市场上的插件分类页面。