工作90:富文本编辑器使用篇wangedit
生活随笔
收集整理的這篇文章主要介紹了
工作90:富文本编辑器使用篇wangedit
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
WangEdit組件
<template lang="html"><div class="editor"><div ref="toolbar" class="toolbar"></div><div ref="editor" class="text"></div></div> </template><script> import E from 'wangeditor' export default {name: 'EditorBar',data() {return {// uploadPath,editor: null,info_: null}},model: {prop: 'value',event: 'change'},props: {value: {type: String,default: ''},isClear: {type: Boolean,default: false}},watch: {isClear(val) {// 觸發清除文本域內容if (val) {this.editor.txt.clear()this.info_ = null}},value: function(value) {if (value !== this.editor.txt.html()) {this.editor.txt.html(this.value)}}//value為編輯框輸入的內容,這里我監聽了一下值,當父組件調用得時候,如果給value賦值了,子組件將會顯示父組件賦給的值},mounted() {this.seteditor()this.editor.txt.html(this.value)},methods: {seteditor() {// http://192.168.2.125:8080/admin/storage/createthis.editor = new E(this.$refs.toolbar, this.$refs.editor)this.editor.config.uploadImgShowBase64 = false // base 64 存儲圖片this.editor.config.uploadImgServer = 'http://otp.cdinfotech.top/file/upload_images'// 配置服務器端地址this.editor.config.uploadImgHeaders = { }// 自定義 headerthis.editor.config.uploadFileName = 'file' // 后端接受上傳文件的參數名this.editor.config.uploadImgMaxSize = 2 * 1024 * 1024 // 將圖片大小限制為 2Mthis.editor.config.uploadImgMaxLength = 6 // 限制一次最多上傳 3 張圖片this.editor.config.uploadImgTimeout = 3 * 60 * 1000 // 設置超時時間// 配置菜單this.editor.config.menus = ['head', // 標題'bold', // 粗體'fontSize', // 字號'fontName', // 字體'italic', // 斜體'underline', // 下劃線'strikeThrough', // 刪除線'foreColor', // 文字顏色'backColor', // 背景顏色'link', // 插入鏈接'list', // 列表'justify', // 對齊方式'quote', // 引用'emoticon', // 表情'image', // 插入圖片'table', // 表格'video', // 插入視頻'code', // 插入代碼'undo', // 撤銷'redo', // 重復'fullscreen' // 全屏]this.editor.config.uploadImgHooks = {fail: (xhr, editor, result) => {// 插入圖片失敗回調},success: (xhr, editor, result) => {// 圖片上傳成功回調},timeout: (xhr, editor) => {// 網絡超時的回調},error: (xhr, editor) => {// 圖片上傳錯誤的回調},customInsert: (insertImg, result, editor) => {// 圖片上傳成功,插入圖片的回調//result為上傳圖片成功的時候返回的數據,這里我打印了一下發現后臺返回的是data:[{url:"路徑的形式"},...]// console.log(result.data[0].url)//insertImg()為插入圖片的函數//循環插入圖片// for (let i = 0; i < 1; i++) {// console.log(result)let url = "http://otp.cdinfotech.top"+result.urlinsertImg(url)// }}}this.editor.config.onchange = (html) => {this.info_ = html // 綁定當前逐漸地值this.$emit('change', this.info_) // 將內容同步到父組件中}// 創建富文本編輯器this.editor.create()}} } </script><style lang="css"> .editor {width: 100%;margin: 0 auto;position: relative;z-index: 0; } .toolbar {border: 1px solid #ccc; } .text {border: 1px solid #ccc;min-height: 500px; } </style>父組件引入
<template><editor-bars v-model="detail" :isClear="isClear" @change="change"></editor-bars><!-- <wang-edit></wang-edit>--> </template> methods: {change(val) {console.log(val)},}, return {isClear: false,detail:""};運行結果
總結
以上是生活随笔為你收集整理的工作90:富文本编辑器使用篇wangedit的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 博图v14编程c语言教程_10个步骤完成
- 下一篇: 华为手表广告营销案例和广告策划案例PPT