\n", "datePublished": "2018-06-20T08:29:16Z", "commentCount": 0, "mainEntityOfPage": "https://www.v2ex.com/t/464451", "author": {"url": "https://www.v2ex.com/member/ioioioioioioi", "@type": "Person", "name": "ioioioioioioi"}, "headline": "Vue.js Summernote.js component 如何使 v-if 工作?\r\n\r\n这个插件,在一个页面会调用多次,希望只显示 model 有内容的", "@type": "DiscussionForumPosting", "url": "https://www.v2ex.com/t/464451", "isPartOf": {"url": "https://www.v2ex.com/go/qna", "@type": "WebPage", "name": "问与答"}, "@context": "https://schema.org", "dateModified": "2018-06-20T08:32:25Z"}
<!-- Reference: https://github.com/StefanNeuser/vuejs2-summernote-component/blob/master/src/Summernote.js -->
<template>
<textarea v-if="model" :name="name">{{ model }}</textarea>
</template>
<script>
module.exports = {
props: {
model: {
required: true,
},
name: {
type: String,
},
height: {
default: '400'
}
},
mounted() {
let config = {
height: this.height
};
let vm = this;
config.callbacks = {
onInit: function () {
$(vm.$el).summernote("code", vm.model);
},
onChange: function () {
vm.$emit('update:model', $(vm.$el).summernote('code'));
},
onBlur: function () {
vm.$emit('update:model', $(vm.$el).summernote('code'));
}
};
$(this.$el).summernote(config);
}
}
</script>
<style scoped>
</style>