我一直在努力让 VueJS 和 TinyMCE 一起工作。我得出的结论是,使用指令是可行的方法。
到目前为止,我已经能够将主体作为指令参数传入,并且 tinyMCE 设置内容。但是,我无法让两种方式绑定工作。我也担心基于tinyMCE api我做的事情完全错误。
我假设的相关 tinyMCE 函数是:
http://community.tinymce.com/wiki.php/api4:method.tinymce.Editor.setContent
// Sets the content of a specific editor (my_editor in this example)
tinymce.get('my_editor').setContent(data);
Run Code Online (Sandbox Code Playgroud)
和
http://community.tinymce.com/wiki.php/api4:method.tinymce.Editor.getContent
// Get content of a specific editor:
tinymce.get('content id').getContent()
Run Code Online (Sandbox Code Playgroud)
<div id="app">
<h3>This is the tinyMCE editor</h3>
<textarea id="editor" v-editor :body="body"></textarea>
<hr>
<p>This input field is properly binded</p>
<input v-model="body">
<hr>
<pre>data binding: {{ body }} </pre>
</div>
Run Code Online (Sandbox Code Playgroud)
tinymce.init({
selector:'#editor',
});
Vue.directive('editor', {
twoWay: true,
params: ['body'],
bind: function () { …Run Code Online (Sandbox Code Playgroud)