Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility with Vue.js 2.0 #14

Open
ninmesara opened this issue Oct 1, 2016 · 20 comments
Open

Compatibility with Vue.js 2.0 #14

ninmesara opened this issue Oct 1, 2016 · 20 comments

Comments

@ninmesara
Copy link

ninmesara commented Oct 1, 2016

Is vue-html-editor compatible with Vue.js 2.0? I'm using Vue.js 2.0 and I'm getting the following error:

[Vue warn]: Failed to mount component: template or render function not defined. (found in component )

@ninmesara
Copy link
Author

After fixing some issues with my setup, this turned out to be something else.
On the other hand, this extension is really incompatible with vuejs 2.0:

  • it doesn't compile the template, thus dependening on vuejs's runtime (which is undesirable), but porbably easy to fix.
  • it modifies the props passed as arguments (which sets a big warning and might break things).

@cgarnier
Copy link

You need to migrate some stuff too. Like rename ready to mounted.

@vitobotta
Copy link

Hi @ninmesara , did you manage to get this to work with 2.0?

@ninmesara
Copy link
Author

I ended up forking it and making a private version with more customization options. My version uses single file components (in order to be compatible with the new version of vuejs's default runtime) and uses the v-model directive, which is the standard way of handling input in vuejs 2.0. I'll submit a pull request when I have the time.

@rlambertsen
Copy link

@ninmesara Could you maybe share the forked version with us? Love to see it

@Chalkin
Copy link

Chalkin commented Nov 12, 2016

Yep, please share the repo! I would need it as well

@Paolocargnin
Copy link

Yeah @ninmesara Hi want that too!

@JapSeyz
Copy link

JapSeyz commented Dec 9, 2016

@ninmesara Any updates on this?

@rlambertsen
Copy link

Nope lol

@fritx
Copy link

fritx commented Dec 27, 2016

+1... Here is some helpful references:

@tooppoo
Copy link

tooppoo commented Jan 21, 2017

I tried to fix this issues, and created a pull request #16.
(not fixed test codes yet.)

@MatheusGodinho
Copy link

Some expectations with @tooppoo PR will be accepted?

@todayqq
Copy link

todayqq commented Feb 17, 2017

@ninmesara Can you share it?

@renatoneri
Copy link

If someone wants, works in v2:

<script>
export default {
    data() {
        return {
            isChanging: false,
            control: null,
            text: ''
        }
    },
    replace: true,
    inherit: false,
    template: '<textarea v-model="text" class="form-control" :name="name"></textarea>',
    props: {
        value: {
            required: false
        },
        language: {
            type: String,
            required: false,
            default: 'en-US'
        },
        height: {
            type: Number,
            required: false,
            default: 160
        },
        minHeight: {
            type: Number,
            required: false,
            default: 160
        },
        maxHeight: {
            type: Number,
            required: false,
            default: 800
        },
        name: {
            type: String,
            required: false,
            default: ''
        },
        toolbar: {
            type: Array,
            required: false,
            default() {
                return [
                    ['font', ['bold', 'italic', 'underline', 'clear']],
                    ['fontsize', ['fontsize']],
                    ['para', ['ul', 'ol', 'paragraph']],
                    ['color', ['color']],
                    ['insert', ['link', 'picture', 'hr']]
                ];
            }
        }
    },
    watch: {
        text(val) {
            this.$emit('input', val)
        },
        value(newVal) {
            this.text = newVal;
            if (this.minHeight > this.height) {
                this.minHeight = this.height;
            }
            if (this.maxHeight < this.height) {
                this.maxHeight = this.height;
            }

            var that = this;

            this.control =  $(this.$el);
            this.control.summernote({
                lang: this.language,
                height: this.height,
                minHeight: this.minHeight,
                maxHeight: this.maxHeight,
                toolbar: this.toolbar,
                callbacks: {
                    onInit: function() {
                        that.control.summernote('code', that.text);
                    }
                }
            }).on('summernote.change', function() {
                if (!that.isChanging) {
                    that.isChanging = true;
                    var code = that.control.summernote('code');
                    that.text = (code === null || code.length === 0 ? null : code);
                    that.$nextTick(function() {
                        that.isChanging = false;
                    });
                }
            });
        }
    }
};
</script>

Html:

<summernote v-model="form.texto"></summernote>

@todayqq
Copy link

todayqq commented Mar 16, 2017

@ninmesara I received your email, thank you for your sharing, can become the friend with you?

@anselmobattisti
Copy link

anselmobattisti commented Mar 17, 2017

@renatoneri your code works, thanks! but my the editor only appear after some key be pressed inside the textarea. Some idea why this is happening?

@renatoneri
Copy link

renatoneri commented Mar 18, 2017

Humm...
In my case, my v-model have always a inicial value that trigger the watch and load summernote.
Try send null or a empty value through v-model on load.

I'll try to change that after.

If that don't work, verify if you loaded summernote.js before my script.

Sorry for my bad english.

@malisit
Copy link

malisit commented Apr 22, 2017

You can take a look at my solution. Works perfectly with vue 2. link
Thanks.

@coxlr
Copy link

coxlr commented Jul 13, 2017

@anselmobattisti where you able to get the version from @renatoneri to work fully? I am having the same issue as you, in that the editor only renders once a key has been pressed in the textarea.

@michaeljcoyne
Copy link

michaeljcoyne commented May 12, 2021

I have rewritten to work on init: seems to work fine.

`<script>
require('summernote');
export default {
data() {
return {
isChanging: false,
control: null,
text: '',
summerData: '',
}
},
replace: true,
inherit: false,
template: '<textarea :id="id" v-model="text" class="form-control" :name="name"></textarea>',
props: {
id: {
required: true,
type: String,
},
value: {
required: false,
type: String,
},
data: {
type: String,
required: true
},
language: {
type: String,
required: false,
default: 'en-US'
},
height: {
type: Number,
required: false,
default: 160
},
minHeight: {
type: Number,
required: false,
default: 160
},
maxHeight: {
type: Number,
required: false,
default: 800
},
name: {
type: String,
required: false,
default: ''
},
toolbar: {
type: Array,
required: false,
default() {
return [
['font', ['bold', 'italic', 'underline', 'clear']],
['fontsize', ['fontsize']],
['para', ['ul', 'ol', 'paragraph']],
['color', ['color']],
['insert', ['link', 'picture', 'hr']]
];
}
}
},
watch: {
text(val) {
this.$emit('input', val)
},
value(newVal) {
this.text = newVal;
}
},

methods: {
    initSummer(id) {

        if (this.minHeight > this.height) {
            this.minHeight = this.height;
        }
        if (this.maxHeight < this.height) {
            this.maxHeight = this.height;
        }

        this.control = $('#' + id);
        this.control.summernote({
            lang: this.language,
            height: this.height,
            minHeight: this.minHeight,
            maxHeight: this.maxHeight,
            toolbar: this.toolbar,
            callbacks: {
                onInit: () => {
                    this.control.summernote('code', this.text);
                }
            }
        }).on('summernote.change', () => {
            if (!this.isChanging) {
                this.isChanging = true;
                let code = this.control.summernote('code');
                this.text = (code === null || code.length === 0 ? null : code);
                this.$nextTick( ()=> {
                    this.isChanging = false;
                });
            }
        });
    }
},
mounted() {
    this.text = this.data;
    this.initSummer(this.id);
}

};
</script>
`

<summernote :id="'title'" :data="form.title" v-model="form.title"></summernote>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests