指令
该指令的作用是dom衬着后触发,由于非vue的插件有的是dom必需存在的情况下才能够实行
Vue.directive('loaded-callback', {
inserted: function (el, binding, vnode) {
binding.value(el, binding, vnode)
}
})
装置kindeditor
npm install kindeditor
kindeditor组件
<template>
<div class="kindeditor">
<textarea class="form-control" ref="kindeditor" v-model="localValue" name="content" v-loaded-callback='initKindeditor'></textarea>
</div>
</template>
<script>
import '../../../../../node_modules/kindeditor/kindeditor-all.js'
import '../../../../../node_modules/kindeditor/lang/zh-CN.js'
import '../../../../../node_modules/kindeditor/themes/default/default.css'
export default {
name: 'kindeditor',
props: ['options', 'value'],
data () {
return {
localValue: ''
}
},
watch: {
localValue: 'updateValue',
value: 'setDefault'
},
created () {
this.setDefault()
},
methods: {
initKindeditor () {
var _this = this
// 默许参数
var options = {
uploadJson: 'upload/image',
width: '100%',
afterChange () {
_this.localValue = this.html()
}
}
// 挪用外部参数
if (_this.options) {
for(var i in _this.options){
options[i] = _this.options[i]
}
}
KindEditor.create(_this.$refs.kindeditor,options);
},
// 设置初始值
setDefault () {
this.localValue = this.value
},
// 修正父件的值
updateValue () {
this.$emit('input',this.localValue)
}
}
}
</script>
用法
<kindeditor :options="options" v-model="content"></kindeditor>