So lately i have been trying to add grapesjs editor in my vuejs project, and things didn't go as planned, i can't see the editor in the browser, and the tag that is supposed to contain the editor is empty. This is my editor configuration:
<template>
<div ref="canvas"></div>
</template>
<script setup>
import grapesjs from "grapesjs";
import "grapesjs/dist/css/grapes.min.css";
const canvas = ref(null)
const editor = grapesjs.init(
{
container: canvas.value,
fromElement: true, // Load existing HTML from the container
storageManager: {
type: "local", // Enable saving and loading from local storage
autosave: true, // Enable autosave
autoload: true, // Load previously saved data
},
canvas: {
styles: [
// Custom canvas styles
],
scripts: [
// custom scripts
],
},
plugins: ["gjs-preset-webpage"],
pluginsOpts: {
"gjs-preset-webpage": {
// Options for the preset plugin
},
},
});
</script>
Note: i have tried this configuration in another vue3 project(that uses < script> syntax btw) and it worked:
<template>
<div ref="editor"></div>
</template>
<script>
import grapesjs from "grapesjs";
import "grapesjs/dist/css/grapes.min.css";
export default {
name: app,
data() {
return {};
},
mounted() {
const editor = grapesjs.init({
container: this.$refs.editor,
fromElement: true, // Load existing HTML from the container
storageManager: {
type: "local", // Enable saving and loading from local storage
autosave: true, // Enable autosave
autoload: true, // Load previously saved data
},
canvas: {
styles: [
// Custom canvas styles
],
scripts: [
// custom scripts
],
},
plugins: ["gjs-preset-webpage"],
pluginsOpts: {
"gjs-preset-webpage": {
// Options for the preset plugin
},
},
});
},
};
</script>
I have tried < script> version in my current project as well and it works, i'm kinda sure the issue is related to the < script setup> syntaxe.
Can anyone please tell me what could be the reason the editor is not loaded int the first case and how could i resolve this issue?