vue中使用Tinymce的示例代碼
1、安裝tinymce編輯器
npm i tinymce npm i @tinymce/tinymce-vue
或:
yarn add tinymce yarn add @tinymce/tinymce-vue
2、配置中文語言包
地址:中文語言包
注:最好將語言包放在public/langs/或static/langs/目錄下,下面組件將會引用
3、封裝組件
在components 目錄下新建 tinymce.vue
<template>
<div>
<Editor :id="tinymceId" :init="init" :disabled="disabled" v-model="myValue"></Editor>
</div>
</template>
<script>
//引入tinymce-vue
import Editor from '@tinymce/tinymce-vue'
//公共的圖片前綴
//import Global from "./Global";
export default {
components: { Editor },
props: {
//編號
id: {
type: String
},
//內(nèi)容
value: {
type: String,
default: ''
},
//是否禁用
disabled: {
type: Boolean,
default: false
},
//插件
plugins: {
type: [String, Array],
default: 'preview searchreplace autolink directionality visualblocks visualchars fullscreen image link media code codesample table charmap pagebreak nonbreaking anchor insertdatetime advlist lists wordcount help emoticons autosave autoresize formatpainter',
},
//工具欄
toolbar: {
type: [String, Array],
default: 'code undo redo restoredraft | fullscreen | cut copy paste pastetext | forecolor backcolor bold italic underline strikethrough link anchor | alignleft aligncenter alignright alignjustify outdent indent | \
styleselect formatselect fontselect fontsizeselect | bullist numlist | blockquote subscript superscript removeformat | \
table image media charmap emoticons hr pagebreak insertdatetime print preview | bdmap indent2em lineheight formatpainter axupimgs',
}
},
data() {
let that = this;
return {
tinymceId: this.id || 'vue-tinymce' + Date.parse(new Date()),
myValue: this.value,
init: {
//漢化,路徑是自定義的
language_url: '/tinymce/langs/zh_CN.js',
language: 'zh_CN',
//皮膚
skin: 'oxide',
//插件
plugins: this.plugins,
//工具欄
toolbar: this.toolbar,
//高度
height: 500,
//圖片上傳
images_upload_handler: function (blobInfo, success, failure) {
//文件上傳的formData傳遞
let formData = new FormData();
formData.append('file', blobInfo.blob(), blobInfo.filename());
//上傳的api,和后端配合,返回的是圖片的地址,然后加上公共的圖片前綴
that.$api.system.uploadImage(formData).then(res => {
var url = "tt"http://Global.baseUrlImg + res;
console.log(url)
success(url)
}).catch(res => {
failure('圖片上傳失敗')
});
}
}
}
},
methods: {
},
watch: {
//監(jiān)聽內(nèi)容變化
value(newValue) {
this.myValue = newValue
},
myValue(newValue) {
this.$emit('input', newValue)
}
}
}
</script>
<style>
.tox-notifications-container {
display: none;
}
/*在頁面正常使用時不用加這個樣式,在彈窗使用時,要加這個樣式,因為使用彈窗,z-index層數(shù)比較低,工具欄的一些工具不能使用,要將z-index層數(shù)提高。*/
.tox.tox-silver-sink.tox-tinymce-aux {
z-index: 2100 !important;
}</style>4、引用組件
新建test.vue
<template>
<div>
<TinymceEditor :value="content" @input="newContent"></TinymceEditor>
</div>
</template>
<script>
import TinymceEditor from "./components/tinymce.vue"
export default {
components: {
TinymceEditor
},
data() {
return {
content: ""
}
},
methods: {
// 獲取富文本的內(nèi)容
newContent(val) {
this.content = val; // 直接更新 content 屬性
}
}
}
</script>注:文件引入路徑是關(guān)鍵
到此這篇關(guān)于vue中使用Tinymce的文章就介紹到這了,更多相關(guān)vue使用Tinymce內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
axios全局請求參數(shù)設(shè)置,請求及返回攔截器的方法
下面小編就為大家分享一篇axios全局請求參數(shù)設(shè)置,請求及返回攔截器的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-03-03
vue axios基于常見業(yè)務(wù)場景的二次封裝的實現(xiàn)
這篇文章主要介紹了vue axios基于常見業(yè)務(wù)場景的二次封裝的實現(xiàn),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-09-09
vuex中this.$store.commit和this.$store.dispatch的基本用法實例
在vue的項目里常常會遇到父子組件間需要進(jìn)行數(shù)據(jù)傳遞的情況,下面這篇文章主要給大家介紹了關(guān)于vuex中this.$store.commit和this.$store.dispatch的基本用法的相關(guān)資料,需要的朋友可以參考下2023-01-01
Vue.js構(gòu)建你的第一個包并在NPM上發(fā)布的方法步驟
這篇文章主要介紹了Vue.js構(gòu)建你的第一個包并在NPM上發(fā)布的方法步驟,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-05-05
手寫Vue源碼之?dāng)?shù)據(jù)劫持示例詳解
這篇文章主要給大家介紹了手寫Vue源碼之?dāng)?shù)據(jù)劫持的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-01-01

