英文:
How to add an option for js code in grapesjs?
问题
现在我想要导出我的JS代码?应该如何做?
我注意到在块管理器中,如果我们将内容编辑如下:
editor.BlockManager.add("sample input field", {
label: "input-field",
category: "sample",
content: {
script: "我的脚本"
}
});
脚本将嵌入到我的HTML文件中,但如果我将其编辑为以下内容:
content:`一些HTML代码
<script type="text/javascript" myscript></script>`
我无法在我的HTML文件中获取脚本内容....如何将脚本嵌入到内容中?
为什么它没有显示在提取的HTML文件中?
英文:
Now I want my JS code also to be exported? How is this done?
I have seen that in the block manager if we edit the content as follows
editor.BlockManager.add("sample input field", {
label: "input-field",
category: "sample",
content: {
script:"my script"
}
});
the script is embedded in my HTML file but if I edit it as follows
content:` some HTML code
<script type="text/javascript" myscript></script>`
I do not get the script content in my HTML file....how to get the script embedded in the content?
Why is it not being displayed in the extracted HTML file?
答案1
得分: 4
你需要在初始化你的grapesjs编辑器时使用allowScripts配置选项。
const editor = grapesjs.init({
... // 其余的grapesjs配置
allowScripts: 1,
});
默认情况下脚本是禁用的,但这个选项会启用它们。
英文:
You need to use the allowScripts config option when initializing your grapesjs editor.
const editor = grapesjs.init({
... // the rest of your grapesjs config
allowScripts: 1,
});
Scripts are disabled by default, but this option turns them on.
答案2
得分: 0
创建一个自定义代码。您可以查看默认视图代码,在那里有一个名为buildEditor的函数,用于完成所有配置。还需要传递HTML、CSS和JS。
const oHtmlEd = buildEditor('htmlmixed', 'hopscotch', 'HTML', editor);
const oCsslEd = buildEditor('css', 'hopscotch', 'CSS', editor);
const oJSlEd = buildEditor('js', 'hopscotch', 'JS', editor);
英文:
Create a custom code. You can check the default view code, in that buildEditor function is there where all config is done. Along with HTML, CSS, pass Js also
const oHtmlEd = buildEditor('htmlmixed', 'hopscotch', 'HTML', editor);
const oCsslEd = buildEditor('css', 'hopscotch', 'CSS', editor);
const oJSlEd = buildEditor('js', 'hopscotch', 'JS', editor);
答案3
得分: 0
const editor = grapesjs.init({
canvas: {
scripts: ['https://.../somelib.min.js'],
// The same would be for external styles
styles: ['https://.../ext-style.min.css'],
}
});
英文:
const editor = grapesjs.init({
canvas: {
scripts: ['https://.../somelib.min.js'],
// The same would be for external styles
styles: ['https://.../ext-style.min.css'],
}
});
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论