0

So i have ask before about integration for summernote with vue.js and already been answered in here and it works flawlessly with v-model binding.

But now when I tried to create edit page and load the data from database, it just not showing those data to summernote

first I fetchData in beforeMount()

beforeMount(){
    if(this.$route.meta.mode === 'edit'){
        this.initialize = '/api/artikel/edit/' + this.$route.params.id;
        this.store = '/api/artikel/update/' + this.$route.params.id;
        this.method = 'put';
    }
    this.fetchData();
},

and then here is my fetchData methods

fetchData(){
    var vm = this
    axios.get(this.initialize)
        .then(function(response){
            Vue.set(vm.$data, 'form', response.data.form);
            Vue.set(vm.$data, 'rules', response.data.rules);
            Vue.set(vm.$data, 'option', response.data.option);
        })
        .catch(function(error){
        })
},

and then in my form i put this summernote component

<app-summernote
        name="editor"
        :model="form.content"
        :config="summernoteconfig"
        @change="value => { form.content = value }"
    ></app-summernote>

and here is my app-summernote modules

    module.exports = {
    template: '<textarea :name="name"></textarea>',
    props: {
        model: {
            required: true,
        },
        name: {
            type: String,
            required: true,
        },
        config: {
            type: Object,
            default: {}
        }
    },
    mounted() {
        let vm = this;
        let config = this.config;
        config.callbacks = {
            onInit: function () {
                $(vm.$el).summernote("code", vm.model);
            },
            onChange: function () {
                vm.$emit('change', $(vm.$el).summernote('code'));
            },
            onBlur: function () {
                vm.$emit('change', $(vm.$el).summernote('code'));
            }
        };
        $(this.$el).summernote(config);
    },
}

and it should be showing data from form.content into summernote, but it's not working.

1 Answer 1

1

I managed to solve this by using a watcher on the summernote component.

watch: {
model: (val) => {
  $('#summernote').summernote("code", val);
}

You also need to set an id for the text field to get this work.

Sign up to request clarification or add additional context in comments.

1 Comment

Did you notice that this is causing the editor to invert the text?, and please how did you solve this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.