reactjsvue.jsbuildergrapesjs

i'm using grapesjs and i want to save data into my database but the url that grapesjs send is the url of the page


i want to save data into my database but the url that grapesjs send is the url of the page not the url that i provid in the storemanager urlstore

this is my code

import 'grapesjs/dist/css/grapes.min.css';
import plugin from 'grapesjs-blocks-basic';
import { computed, onMounted, ref } from 'vue';
import grapesjs from 'grapesjs';
import { useForm } from '@inertiajs/vue3';
// import 'grapesjs-ckeditor';
// import 'grapesjs-lory-slider';
import presetplugin from 'grapesjs-preset-webpage';


const props = defineProps({
    page: Object
})
const editorRef = ref(null);
const editorhtml = ref(null)
const projectEndpoint = `http://127.0.0.1:8003/pages/store`;
onMounted(() => {
    const editor = grapesjs.init({
        container: '#editor',
        plugins: [plugin, presetplugin],
        autosave: false,
        storageManager: {
            type: 'remote',
            urlLoad: 'http://127.0.0.1:8003/api/pages/store',
            urlStore:'http://127.0.0.1:8003/api/pages/store',
            contentTypeJson: true,
            storeComponents: true,
            storeStyles: true,
            storeHtml: true,
            storeCss: true,
            stepsBeforeSave: 1,
            headers: {
                'Content-Type': 'application/json'
            },
            id:'my-',
            // onStore: data => ({  data }),
            onLoad: result => result.gjs_data,
        }
        });
    editorRef.value = editor;
});

and this is my controller code

public function store(Request $request)
    {
        Page::find('99972727-ccea-4e48-892e-d63e6e68b884')->update(
            ['gjs_data'=>$request->body]
        );

        return response()->json(['success' => true]);
    }

    public function getpage()
    {
        $page=Page::orderby('created_at','asc')->first();
        return response()->json(json_encode($page->data));
    }

i want to save data in my database


Solution

  • struggled with the same problem then went through the documentation and the RemoteStorage class in the repo, the actual code should be like this:

    storageManager: {
            type: 'remote',
            options:{
                remote: {
                     urlLoad: 'http://127.0.0.1:8003/api/pages/store',
                     urlStore:'http://127.0.0.1:8003/api/pages/store',
                }
            },
            contentTypeJson: true,
            storeComponents: true,
            storeStyles: true,
            storeHtml: true,
            storeCss: true,
            stepsBeforeSave: 1,
            headers: {
                'Content-Type': 'application/json'
            },
            id:'my-',
            // onStore: data => ({  data }),
            onLoad: result => result.gjs_data,
        }