admin管理员组文章数量:1391947
I'm trying to get Vuejs and TinyMCE to work together. I use @tinymce/tinymce-vue package which is the vue integration for TinyMCE. I had followed all the instructions and everything seems to work, I mean I can write properly, insert image... everything except the v-model part.
Here is the simplified template :
<form action="/http://localhost:4000/articles" method="POST">
<input id="data_title" class="input-title" v-model="title" type="text"/>
<editor id="editor" v-model="content"></editor>
<textarea id="data_description" v-model="description" class="input-resume"></textarea>
</form>
Script part :
export default {
data() {
return {
title: "",
description: "",
content:"",
}
},
mounted() {
tinymce.init({
selector: '#editor',
plugins: "image",
toolbar: [
'undo redo | styleselect | bold italic | link image',
'alignleft aligncenter alignright'
]
});
}
I send my data to a Rest API using axios :
axios.post('http://localhost:4000/articles', {
title: this.title,
description: this.description,
content: this.content,
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
},
Everything is ok, no errors. After posting the article, I have a title and a description, but no content. V-model doesn't seem to be bounded to the <editor></editor>
, because in the chrome devtool nothing is happening when I'm writing in it. The others v-model in the form are perfectly working.
Any thoughts?
Thank you for your time fellows :)
I'm trying to get Vuejs and TinyMCE to work together. I use @tinymce/tinymce-vue package which is the vue integration for TinyMCE. I had followed all the instructions and everything seems to work, I mean I can write properly, insert image... everything except the v-model part.
Here is the simplified template :
<form action="/http://localhost:4000/articles" method="POST">
<input id="data_title" class="input-title" v-model="title" type="text"/>
<editor id="editor" v-model="content"></editor>
<textarea id="data_description" v-model="description" class="input-resume"></textarea>
</form>
Script part :
export default {
data() {
return {
title: "",
description: "",
content:"",
}
},
mounted() {
tinymce.init({
selector: '#editor',
plugins: "image",
toolbar: [
'undo redo | styleselect | bold italic | link image',
'alignleft aligncenter alignright'
]
});
}
I send my data to a Rest API using axios :
axios.post('http://localhost:4000/articles', {
title: this.title,
description: this.description,
content: this.content,
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
},
Everything is ok, no errors. After posting the article, I have a title and a description, but no content. V-model doesn't seem to be bounded to the <editor></editor>
, because in the chrome devtool nothing is happening when I'm writing in it. The others v-model in the form are perfectly working.
Any thoughts?
Thank you for your time fellows :)
Share Improve this question asked Sep 27, 2018 at 13:18 blickblickblickblick 2471 gold badge5 silver badges16 bronze badges4 Answers
Reset to default 3In my case, I came up with this solution :
tinymce.init({
selector:'textarea.tinymce',
setup: function(editor) {
editor.on('change', function () {
editor.save();
editor.getElement().dispatchEvent(new Event('input'));
});
}
})
Why are you using the TinyMCE init()
call in your mounted()
code? The TinyMCE wrapper does that for you and you can pass the init parameter to include the configuration you want.
https://github./tinymce/tinymce-vue#configuring-the-editor
I suspect your mounted()
code is initializing TinyMCE and your Vue model data knows nothing of that - when the wrapper later tries to initialize the editor it fails because its already initialized which leads to the data binding not being in place.
I know this post is a bit old, but for those experiencing this issue, try wrapping your editor ponent tags in a div block like this:
<form action="/http://localhost:4000/articles" method="POST">
<input id="data_title" class="input-title" v-model="title" type="text"/>
<div>
<editor id="editor" v-model="content"></editor>
</div>
<textarea id="data_description" v-model="description" class="input-resume"></textarea>
</form>
This worked for me and I hope it helps.
I think I found a solution. If you are using vue-tinymce-editor
From TinymceVue.vue (in \node_modules\vue-tinymce-editor\src\ponents\TinymceVue.vue) remove this code:
value : function (newValue){
if(!this.isTyping){
if(this.editor !== null)
this.editor.setContent(newValue);
else
this.content = newValue;
}
},
And you don't need to init in mounted()
TinyMCE for Vue is bugged so much sometimes we have to find solutions in sourcefiles :P
本文标签: javascriptVmodel and TinyMCE doesn39t work togetherStack Overflow
版权声明:本文标题:javascript - V-model and TinyMCE doesn't work together - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744698795a2620441.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论