日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > vue >内容正文

vue

vue3 富文本编辑器

發布時間:2023/12/10 vue 48 豆豆
生活随笔 收集整理的這篇文章主要介紹了 vue3 富文本编辑器 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

wangeditor

一、簡單用法

首先:npm install wangeditor --save

<div id="richText" style="height: 400px;background-color: #fff;" ></div> import { ref, onMounted } from 'vue' import E from 'wangeditor' const phoneEditor = ref('') onMounted(() => {phoneEditor.value = new E('#richText')// 上傳圖片到服務器,base64形式phoneEditor.value.config.uploadImgShowBase64 = true// 隱藏網絡圖片phoneEditor.value.config.showLinkImg = false// 創建一個富文本編輯器phoneEditor.value.create()// 富文本內容phoneEditor.value.txt.html() })

二、官網使用步驟

安裝

yarn add @wangeditor/editor-for-vue@next # 或者 npm install @wangeditor/editor-for-vue@next --save

?

<template><div style="border: 1px solid #ccc"><Toolbarstyle="border-bottom: 1px solid #ccc":editor="editorRef":defaultConfig="toolbarConfig":mode="mode"/><Editorstyle="height: 500px; overflow-y: hidden"v-model="valueHtml":defaultConfig="editorConfig":mode="mode"@onCreated="handleCreated"/></div> </template> <script> import '@wangeditor/editor/dist/css/style.css' // 引入 cssimport { onBeforeUnmount, ref, shallowRef, onMounted } from 'vue' import { Editor, Toolbar } from '@wangeditor/editor-for-vue' export default {components: { Editor, Toolbar },setup () {// 編輯器實例,必須用 shallowRefconst editorRef = shallowRef()// 內容 HTMLconst valueHtml = ref('<p>hello</p>')// 模擬 ajax 異步獲取內容onMounted(() => {setTimeout(() => {valueHtml.value = '<p>模擬 Ajax 異步設置內容</p>'}, 1500)})const toolbarConfig = { }const editorConfig = { placeholder: '請輸入內容...' }// 組件銷毀時,也及時銷毀編輯器onBeforeUnmount(() => {const editor = editorRef.value if (editor == null) returneditor.destroy()})const handleCreated = (editor) => {editorRef.value = editor // 記錄 editor 實例,重要!}return {editorRef,valueHtml,mode: 'default',toolbarConfig,editorConfig,handleCreated}} } </script>

?注意:如果需要自定義工具欄的配置,可以在toolbarConfig里面寫入。如果想要添加指定菜單,使用toolbarKeys,如果需要排除某一些菜單,使用excludeKeys即可。如:

const toolbarConfig = {toolbarKeys: ['bold', // 加粗'italic', // 斜體'through', // 刪除線'underline', // 下劃線'bulletedList', // 無序列表'numberedList', // 有序列表'color', // 文字顏色'insertLink', // 插入鏈接'fontSize', // 字體大小'lineHeight', // 行高'uploadImage', // 上傳圖片'delIndent', // 縮進'indent', // 增進'deleteImage',//刪除圖片'divider', // 分割線'insertImage', // 網絡圖片'insertTable', // 插入表格'justifyCenter', // 居中對齊'justifyJustify', // 兩端對齊'justifyLeft', // 左對齊'justifyRight', // 右對齊'undo', // 撤銷'redo', // 重做'clearStyle', // 清除格式'fullScreen' // 全屏] } const toolbarConfig = {excludeKeys: ['bgColor', // 背景色'blockquote', // 引用'codeBlock', // 代碼段'emotion', // 表情'fontFamily', // 字體'headerSelect' // 標題 ]}

傳送門:wangEditor

總結

以上是生活随笔為你收集整理的vue3 富文本编辑器的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。