vue中使用tinymce及插件powerpaste的使用
一、版本
"@tinymce/tinymce-vue": "^3.0.1"
"tinymce": "^5.0.2",
"vue": "^2.6.11",
powerpaste 必須單獨(dú)另外下載 !??!
二、vue中的使用
1、vue中下載tinymce
npm itinymce@5.0.2 -S
2、在界面引入tinymce
語言包下載地址:https://www.tiny.cloud/get-tiny/language-packages/
1、tinymce的封裝
<template>
<div class="tinymce-editor" style="height: calc(100% - 56px);">
<editor v-model="myValue" :init="init" :disabled="disabled" @onClick="onClick" id="mytextarea"></editor>
</div>
</template>
<script>
import tinymce from 'tinymce/tinymce'
import Editor from '@tinymce/tinymce-vue'
import 'tinymce/themes/silver/theme'
import 'tinymce/plugins/lists' // 列表插件
import 'tinymce/plugins/code' // 源代碼插件
import 'tinymce/plugins/pagebreak' // 分頁符插件
import 'tinymce/plugins/charmap' // 特殊符號插件
import 'tinymce/plugins/emoticons' // 表情插件
import 'tinymce/plugins/save' // 保存插件
import 'tinymce/plugins/preview' // 預(yù)覽插件
// import 'tinymce/plugins/print' // 打印
import 'tinymce/plugins/image' // 上傳圖片插件
import 'tinymce/plugins/media' // 視頻插件
import 'tinymce/plugins/link' // 鏈接插件
import 'tinymce/plugins/anchor' // 錨點(diǎn)插件
import 'tinymce/plugins/codesample' // 代碼插件
import 'tinymce/plugins/table' // 表格插件
import 'tinymce/plugins/searchreplace' // 查找、替換插件
import 'tinymce/plugins/hr' // 水平分割線插件
import 'tinymce/plugins/insertdatetime' // 時間日期插件
// import 'tinymce/plugins/paste' // 粘體插件
import 'tinymce/plugins/wordcount' // 字?jǐn)?shù)統(tǒng)計插件
import 'tinymce/plugins/fullscreen' // 全屏插件
import 'tinymce/plugins/help' // 幫助插件
export default {
components: {
Editor,
},
props: {
//傳入一個value,使組件支持v-model綁定
value: {
type: String,
default: '',
},
disabled: {
type: Boolean,
default: false,
},
plugins: {
type: [String, Array],
default:
'lists code pagebreak charmap emoticons save preview print image media link powerpaste ' +
'anchor codesample table wordcount fullscreen help searchreplace hr insertdatetime',
},
toolbar: {
type: [String, Array],
default:
'| formatselect fontselect fontsizeselect ' +
'| undo redo ' +
'| code bold italic underline strikethrough ' +
'| alignleft aligncenter alignright alignjustify ' +
'| outdent indent numlist bullist insertdatetime ' +
'| table forecolor backcolor removeformat ' +
'| hr searchreplace pagebreak charmap ' +
'| fullscreen ' +
'| link anchor codesample ',
},
},
data() {
return {
//初始化配置
init: {
language_url: '/tinymce/zh-Hans.js',
language: 'zh-Hans',
skin_url: '/skins/ui/oxide',
content_css: '/skins/content/default/content.css',
height: '100%',
plugins: this.plugins,
toolbar: this.toolbar,
menubar: true,
placeholder: '請輸入內(nèi)容',
branding: false, // 隱藏右下角技術(shù)支持
fontsize_formats:
'12px 14px 16px 18px 24px 36px 48px 56px 72px',
paste_data_images: true, // 是否允許黏貼圖片
font_formats:
'微軟雅黑=Microsoft YaHei,Helvetica Neue,PingFang SC,sans-serif;蘋果蘋方=PingFang SC,Microsoft YaHei,sans-serif;宋體=simsun,serif;仿宋體=FangSong,serif;黑體=SimHei,sans-serif;Arial=arial,helvetica,sans-serif;Arial Black=arial black,avant garde;Book Antiqua=book antiqua,palatino;',
resize: true,
zIndex: 11101,
theme: 'silver', //主題
insertdatetime_formats: [
'%H點(diǎn)%M分',
'%Y年%m月%d日',
'%Y年%m月%d日 %H點(diǎn)%M分',
'%Y-%m-%d %H:%M',
], // 時間日期格式化
contextmenu: false, // 禁用富文本的右鍵菜單,使用瀏覽器自帶的右鍵菜單
// 添加擴(kuò)展插件
external_plugins: {
powerpaste: '/powerpaste/plugin.min.js',
},
powerpaste_word_import: 'propmt', // 參數(shù)可以是propmt, merge, clear,效果自行切換對比
powerpaste_html_import: 'propmt', // propmt, merge, clear
powerpaste_allow_local_images: true,
},
myValue: this.value,
}
},
mounted() {
tinymce.init({})
},
methods: {
//添加相關(guān)的事件,可用的事件參照文檔=> https://github.com/tinymce/tinymce-vue => All available events
//需要什么事件可以自己增加
onClick(e) {
this.$emit('onClick', e, tinymce)
},
},
watch: {
value(newValue) {
this.myValue = newValue
},
myValue(newValue) {
this.$emit('hangdleEditor', newValue)
},
},
}
</script>
<style scoped>
</style>2、tinymce 組件的使用
<template>
<div style="height: calc(100%)">
<Tinymce id="textAreaContent" class="editor" :value="content" v-on:hangdleEditor="hangdleEditor" />
</div>
</template>
<script>
import Tinymce from '@/public/Tinymce.vue'
export default {
data() {
return {
content: '',
}
},
mounted() {
},
methods: {
hangdleEditor(val) {
this.content = val
},
},
components: {
Tinymce,
},
}
</script>
<style scoped lang="less">
.cont {
height: calc(100% - 60px);
overflow: auto;
.back {
width: 96px;
height: 32px;
line-height: 32px;
background: #ffffff;
border-radius: 16px;
font-size: 18px;
font-weight: 500;
color: #333333;
text-align: center;
cursor: pointer;
margin-bottom: 24px;
}
}
</style>3、powerpaste 插件放入根目錄public下

鏈接:https://dxz.jb51.net/202307/yuanma/tinymce_powerpaste-master_jb51.rar
可以去這個地址下載 powerpaste 插件
4、處理粘貼內(nèi)容時顯示的文本為英文

修改js文件中與顯示彈窗的相同英文內(nèi)容,替換為中文即可
5、效果預(yù)覽

到此這篇關(guān)于vue中使用tinymce,以及插件 powerpaste 的使用的文章就介紹到這了,更多相關(guān)vue使用tinymce內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue 1.0 結(jié)合animate.css定義動畫效果
本文分步驟給大家介紹了Vue 1.0自定義動畫效果,vue1.0代碼結(jié)合animate.css定義動畫,頁面一定要引入animate.cdd,具體實例代碼大家參考下本文2018-07-07
vue3中實現(xiàn)拖拽排序代碼示例(vue-draggable-next的使用)
在Vue3中使用拖拽功能時應(yīng)選用vue-draggable-next插件,傳統(tǒng)的draggable插件不兼容Vue3,可能導(dǎo)致TypeError錯誤,安裝后,需在項目中引入并使用,具體步驟包括安裝插件、引入使用、查看效果和相關(guān)說明,需要的朋友可以參考下2024-09-09
使用vue-element-admin框架從后端動態(tài)獲取菜單功能的實現(xiàn)
​ vue-element-admin是一個純前端的框架,左側(cè)菜單是根據(jù)路由生成的。實際開發(fā)中經(jīng)常需要根據(jù)當(dāng)前登陸人員的信息從后端獲取菜單進(jìn)行展示,本文將詳細(xì)介紹如何實現(xiàn)該功能2021-04-04
Vue引入vuetify框架你需要知道的幾點(diǎn)知識
這篇文章主要介紹了Vue引入vuetify框架你需要知道的幾點(diǎn)知識,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-06-06
vue父組件數(shù)據(jù)更新子組件相關(guān)內(nèi)容未改變問題(用watch解決)
這篇文章主要介紹了vue父組件數(shù)據(jù)更新子組件相關(guān)內(nèi)容未改變問題(用watch解決),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-03-03

