工作108:vue里面wangEdit编辑器使用
生活随笔
收集整理的這篇文章主要介紹了
工作108:vue里面wangEdit编辑器使用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
WangEdit使用?
<template lang="html"><div class="editor"><!--定義的為表頭的屬性--><div ref="toolbar" class="toolbar"></div><!--定義的為表格的屬性--><div ref="editor" class="text"></div></div> </template> <script> /*引入王edit插件*/ import E from 'wangeditor' import {getAction} from "@/api"; export default {name: 'EditorBar',data() {return {editor: null,info_: null,UploadVidio:'',}},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賦值了,子組件將會顯示父組件賦給的值},created() {/*控制上傳圖片的邏輯*/getAction("/content/upload_url/"+1).then(res=>{this.UploadVidio=res.data}).then(res=>{this.seteditor()this.editor.txt.html(this.value)})},methods: {seteditor() {/*選中對應的元素*/this.editor = new E(this.$refs.toolbar, this.$refs.editor)/*設置存儲照片的格式*/this.editor.config.uploadImgShowBase64 = false // base 64 存儲圖片this.editor.config.uploadImgServer =this.UploadVidio// 配置服務器端地址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 = this.UploadVidioinsertImg(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>?
總結
以上是生活随笔為你收集整理的工作108:vue里面wangEdit编辑器使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: plc编程有哪些方法?
- 下一篇: 电子政务之门户建设