国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

vue中使用wangeditor富文本編輯器

這篇具有很好參考價(jià)值的文章主要介紹了vue中使用wangeditor富文本編輯器。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

官方文檔?

項(xiàng)目中要求實(shí)現(xiàn)富文本編輯器取編輯內(nèi)容

這種編輯器有好多選擇了wangeditor富文本編輯器

首先根據(jù)文檔安裝

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

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

再按照官方的指引 cv 如下代碼

<template>
    <div style="border: 1px solid #ccc">
      <Toolbar
        style="border-bottom: 1px solid #ccc"
        :editor="editorRef"
        :defaultConfig="toolbarConfig"
        :mode="mode"
      />
      <Editor
        style="height: 500px; overflow-y: hidden;"
        v-model="valueHtml"
        :defaultConfig="editorConfig"
        :mode="mode"
        @onCreated="handleCreated"
      />
    </div>
</template>

<script>
import '@wangeditor/editor/dist/css/style.css' // 引入 css

import { onBeforeUnmount, ref, shallowRef, onMounted } from 'vue'
import { Editor, Toolbar } from '@wangeditor/editor-for-vue'

export default {
  components: { Editor, Toolbar },
  setup() {
    // 編輯器實(shí)例,必須用 shallowRef
    const editorRef = shallowRef()

    // 內(nèi)容 HTML
    const valueHtml = ref('<p>hello</p>')

    // 模擬 ajax 異步獲取內(nèi)容
    onMounted(() => {
        setTimeout(() => {
            valueHtml.value = '<p>模擬 Ajax 異步設(shè)置內(nèi)容</p>'
        }, 1500)
    })

    const toolbarConfig = {}
    const editorConfig = { placeholder: '請(qǐng)輸入內(nèi)容...' }

    // 組件銷毀時(shí),也及時(shí)銷毀編輯器
    onBeforeUnmount(() => {
        const editor = editorRef.value
        if (editor == null) return
        editor.destroy()
    })

    const handleCreated = (editor) => {
      editorRef.value = editor // 記錄 editor 實(shí)例,重要!
    }

    return {
      editorRef,
      valueHtml,
      mode: 'default', //默認(rèn)模式
      mode: 'simple', //簡(jiǎn)潔模式
      toolbarConfig,
      editorConfig,
      handleCreated
    };
  }
}
</script>    

這個(gè)時(shí)候編輯器的功能已經(jīng)實(shí)現(xiàn)了 如下圖

vue中使用wangeditor富文本編輯器

?但是目前為止他還不是我想要的

因?yàn)檫@個(gè)編輯器我想讓他在彈窗中出現(xiàn),而且我不需要那么多功能

接著更文檔的步子走

vue中使用wangeditor富文本編輯器

?文檔里面既然有這個(gè)那就肯定可以實(shí)現(xiàn)

研究一番發(fā)現(xiàn)弱國(guó)想要怎加或者修改編輯器的功能首先要獲取這個(gè)功能的key

vue中使用wangeditor富文本編輯器

?點(diǎn)擊Deom示例

打開控制臺(tái),輸入toolbar.getConfig().toolbarKeys這個(gè)時(shí)候就可以看到每個(gè)功能的key了

vue中使用wangeditor富文本編輯器

在回個(gè)車

vue中使用wangeditor富文本編輯器

?就可以看到詳細(xì)內(nèi)容了

這個(gè)時(shí)候只需要回到代碼里面添加


    toolbarConfig.toolbarKeys = [
      // 菜單 key
      'headerSelect',

      // 分割線
      '|',

      // 菜單 key
      'bold',
      'italic',
      'color',
      'justifyLeft',
      'justifyRight',
      'justifyCenter'

      // 繼續(xù)配置其他菜單...
    ]

就可以實(shí)現(xiàn)你想要的功能了,如下圖

vue中使用wangeditor富文本編輯器

?我們可通過(guò)toolbarKeys: [], 去實(shí)現(xiàn)顯示哪些菜單,如何排序、分組的功能? ?通過(guò)excludeKeys: []選擇去隱藏哪些菜單

最復(fù)雜的就是上傳圖片了,其實(shí)這個(gè)也很簡(jiǎn)單

看看文檔

一目了然https://www.wangeditor.com/v5/menu-config.html#%E4%B8%8A%E4%BC%A0%E5%9B%BE%E7%89%87return中寫上如下代碼,需要注意的時(shí)上傳圖片后,后端必須返回url圖片的鏈接,否則編輯器中不會(huì)顯示圖片

editorConfig: {
                placeholder: '點(diǎn)擊全屏介紹產(chǎn)品吧...',
                // autoFocus: false,
                // 所有的菜單配置,都要在 MENU_CONF 屬性下
                MENU_CONF: {

                    // 配置字號(hào)
                    // fontSize: [... ],


                    // 圖片上傳
                    uploadImage: {
                        server: '/api/admin/uploade',
                        fieldName: 'img',
                        // 單個(gè)文件的最大體積限制,默認(rèn)為 2M
                        maximgSize: 10 * 1024 * 1024, // 10M
                        // 最多可上傳幾個(gè)文件,默認(rèn)為 100
                        maxNumberOfimgs: 10,
                        // 選擇文件時(shí)的類型限制,默認(rèn)為 ['image/*'] 。如不想限制,則設(shè)置為 []
                        allowedimgTypes: ['image/*'],
                        // 自定義上傳參數(shù),例如傳遞驗(yàn)證的 token 等。參數(shù)會(huì)被添加到 formData 中,一起上傳到服務(wù)端。
                        meta: {
                            // token: 'xxx',
                            // otherKey: 'yyy'
                            // img:''
                        },
                        // 將 meta 拼接到 url 參數(shù)中,默認(rèn) false
                        metaWithUrl: false,

                        // 自定義增加 http  header
                        headers: {
                            // Accept: 'text/x-json',
                            // otherKey: 'xxx'
                        },

                        // 跨域是否傳遞 cookie ,默認(rèn)為 false
                        withCredentials: true,

                        // 超時(shí)時(shí)間,默認(rèn)為 10 秒
                        timeout: 10 * 1000, //10 秒

                        // 上傳前
                        onBeforeUpload(imgs) {
                            ElMessage({
                                message: '圖片正在上傳中,請(qǐng)耐心等待',
                                grouping: true,
                                duration: 0,
                                customClass: 'uploadTip',
                                iconClass: 'el-icon-loading',
                                showClose: true
                            });
                            return imgs;
                        },
                        // 自定義插入圖片
                        customInsert(res, insertFn) {
                            // 因?yàn)樽远x插入導(dǎo)致onSuccess與onFailed回調(diào)函數(shù)不起作用,自己手動(dòng)處理
                            // 先關(guān)閉等待的ElMessage
                            ElMessage.closeAll();

                            if (res.code === 200) {
                                ElMessage.success({
                                    message: "圖片上傳成功",
                                    grouping: true,
                                });
                            } else {
                                ElMessage.error({
                                    message: "圖片上傳失敗,請(qǐng)重新嘗試",
                                    grouping: true,
                                });
                            }
                            // 從 res 中找到 url alt href ,然后插入圖片
                            insertFn(res.data.url);
                            // console.log(res, "res.data")
                        },

                        // 單個(gè)文件上傳成功之后
                        onSuccess(img, res) {
                            console.log(`${img.name} 上傳成功`, res);
                        },

                        // 單個(gè)文件上傳失敗
                        onFailed(img, res) {
                            console.log(`${img.name} 上傳失敗`, res);
                        },

                        // 上傳進(jìn)度的回調(diào)函數(shù)
                        onProgress(progress) {
                            console.log('progress', progress);
                            // progress 是 0-100 的數(shù)字
                        },

                        // 上傳錯(cuò)誤,或者觸發(fā) timeout 超時(shí)
                        onError(img, err, res) {
                            console.log(`${img.name} 上傳出錯(cuò)`, err, res);
                        }
                    },

到這里其實(shí)基本功能已經(jīng)實(shí)現(xiàn)了,那我們?cè)趺幢4妫庉嬈髦械膬?nèi)容呢

需要知道富文本編輯器是所見(jiàn)即所得的文本編輯器,簡(jiǎn)單來(lái)說(shuō)就是文本上面寫的行內(nèi)樣式,那我們?cè)撛鯓颖4孢@些行內(nèi)樣式呢,在這里我是寫成了組件的形式

官方文檔中給出

vue中使用wangeditor富文本編輯器

?methods中寫上

onChange(editor) {
  const text = editor.getHtml()
  this.$emit('update:content', text)
},

當(dāng)內(nèi)容變化是就獲取當(dāng)前行內(nèi)樣式

然后在父組件中監(jiān)聽(tīng)下

  watch: {
    "addlist.content"(value) {
      // console.log(value, "就是這里")
    },
  

在需要的地方

<!-- 編輯器組件 -->
<editor-all v-model:content="addlist.content" :passSon="addlist.content" />
<!-- 編輯器組件結(jié)束 -->

就可以實(shí)現(xiàn)需要的功能啦

完整代碼

<template>
    <div style="border: 1px solid #ccc; margin-top: 10px;z-index:999;width:537px">
        <!-- 工具欄 -->
        <Toolbar style="border-bottom: 1px solid #ccc" :editor="editor" :defaultConfig="toolbarConfig" />
        <!-- 編輯器 -->
        <Editor style="height:200px; overflow-y: hidden;" :defaultConfig="editorConfig" v-model="passSon"
            @onChange="onChange" @onCreated="onCreated" />
    </div>
</template>

<script>
import { ElMessage } from 'element-plus'
import { Editor, Toolbar } from '@wangeditor/editor-for-vue'
export default {
    props: {
        passSon: ''
    },

    data() {
        return {
            editor: null,
            toolbarConfig: {
                /* 顯示哪些菜單,如何排序、分組 */
                // toolbarKeys: [],


                /* 隱藏哪些菜單 */
                excludeKeys: [
                    // '|',
                    'blockquote',
                    'fontSize',
                    'fontFamily',
                    'lineHeight',
                    'bulletedList',
                    'numberedList',
                    'todo',
                    'emotion',
                    'group-video',
                    'group-indent',
                    'group-more-style',
                    'insertTable',
                    'codeBlock',],
            },
            editorConfig: {
                placeholder: '點(diǎn)擊全屏介紹產(chǎn)品吧...',
                // autoFocus: false,
                // 所有的菜單配置,都要在 MENU_CONF 屬性下
                MENU_CONF: {

                    // 配置字號(hào)
                    // fontSize: [... ],


                    // 圖片上傳
                    uploadImage: {
                        server: '/api/admin/uploade',
                        fieldName: 'img',
                        // 單個(gè)文件的最大體積限制,默認(rèn)為 2M
                        maximgSize: 10 * 1024 * 1024, // 10M
                        // 最多可上傳幾個(gè)文件,默認(rèn)為 100
                        maxNumberOfimgs: 10,
                        // 選擇文件時(shí)的類型限制,默認(rèn)為 ['image/*'] 。如不想限制,則設(shè)置為 []
                        allowedimgTypes: ['image/*'],
                        // 自定義上傳參數(shù),例如傳遞驗(yàn)證的 token 等。參數(shù)會(huì)被添加到 formData 中,一起上傳到服務(wù)端。
                        meta: {
                            // token: 'xxx',
                            // otherKey: 'yyy'
                            // img:''
                        },
                        // 將 meta 拼接到 url 參數(shù)中,默認(rèn) false
                        metaWithUrl: false,

                        // 自定義增加 http  header
                        headers: {
                            // Accept: 'text/x-json',
                            // otherKey: 'xxx'
                        },

                        // 跨域是否傳遞 cookie ,默認(rèn)為 false
                        withCredentials: true,

                        // 超時(shí)時(shí)間,默認(rèn)為 10 秒
                        timeout: 10 * 1000, //10 秒

                        // 上傳前
                        onBeforeUpload(imgs) {
                            ElMessage({
                                message: '圖片正在上傳中,請(qǐng)耐心等待',
                                grouping: true,
                                duration: 0,
                                customClass: 'uploadTip',
                                iconClass: 'el-icon-loading',
                                showClose: true
                            });
                            return imgs;
                        },
                        // 自定義插入圖片
                        customInsert(res, insertFn) {
                            // 因?yàn)樽远x插入導(dǎo)致onSuccess與onFailed回調(diào)函數(shù)不起作用,自己手動(dòng)處理
                            // 先關(guān)閉等待的ElMessage
                            ElMessage.closeAll();

                            if (res.code === 200) {
                                ElMessage.success({
                                    message: "圖片上傳成功",
                                    grouping: true,
                                });
                            } else {
                                ElMessage.error({
                                    message: "圖片上傳失敗,請(qǐng)重新嘗試",
                                    grouping: true,
                                });
                            }
                            // 從 res 中找到 url alt href ,然后插入圖片
                            insertFn(res.data.url);
                            // console.log(res, "res.data")
                        },

                        // 單個(gè)文件上傳成功之后
                        onSuccess(img, res) {
                            console.log(`${img.name} 上傳成功`, res);
                        },

                        // 單個(gè)文件上傳失敗
                        onFailed(img, res) {
                            console.log(`${img.name} 上傳失敗`, res);
                        },

                        // 上傳進(jìn)度的回調(diào)函數(shù)
                        onProgress(progress) {
                            console.log('progress', progress);
                            // progress 是 0-100 的數(shù)字
                        },

                        // 上傳錯(cuò)誤,或者觸發(fā) timeout 超時(shí)
                        onError(img, err, res) {
                            console.log(`${img.name} 上傳出錯(cuò)`, err, res);
                        }
                    },
                }
            },
        }
    },
    mounted() {

    },
    methods: {

        onCreated(editor) {
            this.editor = Object.seal(editor) // 【注意】一定要用 Object.seal() 否則會(huì)報(bào)錯(cuò)
        },

        onChange(editor) {
            const text = editor.getHtml()
            this.$emit('update:content', text)
        },
    },

    beforeDestroy() {
        const editor = this.editor
        if (editor == null) return
        editor.destroy() // 組件銷毀時(shí),及時(shí)銷毀 editor ,重要?。?!
    },
    components: { Editor, Toolbar },
}
</script>

<style src="@wangeditor/editor/dist/css/style.css">

</style>

ok文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-426306.html

到了這里,關(guān)于vue中使用wangeditor富文本編輯器的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • VUE2整合富文本編輯器 wangEditor

    2024年02月20日
    瀏覽(35)
  • vue2+wangEditor5富文本編輯器

    vue2+wangEditor5富文本編輯器

    1、安裝使用 安裝 yarn add @wangeditor/editor # 或者 npm install @wangeditor/editor --save yarn add @wangeditor/editor-for-vue # 或者 npm install @wangeditor/editor-for-vue --save ?在main.js中引入樣式 import \\\'@wangeditor/editor/dist/css/style.css\\\' ? 在使用編輯器的頁(yè)面引入js? import { Editor, Toolbar } from \\\"@wangeditor/editor-fo

    2024年01月22日
    瀏覽(20)
  • React----富文本編輯器wangEditor的使用

    wangEditor 5 —— 輕量級(jí) web 富文本編輯器,配置方便,使用簡(jiǎn)單。支持 IE10+ 瀏覽器。 官網(wǎng):www.wangEditor.com 注意: wangeditor都是小寫字母 Editor : 編輯器組件 Toolbar: 菜單欄組件 實(shí)例化編輯器 工具欄配置決定了在工具欄顯示哪些工具,菜單配置決定了該工具使用時(shí)的相關(guān)配置。

    2024年01月21日
    瀏覽(30)
  • HTML——實(shí)現(xiàn)富文本編輯器wangEditor的使用

    HTML——實(shí)現(xiàn)富文本編輯器wangEditor的使用

    背景:最近在寫小說(shuō)項(xiàng)目,關(guān)于發(fā)布文章需要用到富文本編輯器,由于還沒(méi)學(xué)到Vue,最實(shí)用的還是用wangEditor富文本編輯器。 官方文檔:http://www.wangeditor.com/ 使用手冊(cè):創(chuàng)建一個(gè)編輯器 · wangEditor3使用手冊(cè) · 看云 (kancloud.cn) 至于實(shí)現(xiàn)的方式有三種: 一.導(dǎo)入wangEditor.JS 使用方法

    2024年02月11日
    瀏覽(38)
  • vue2+wangEditor5富文本編輯器(圖片視頻上傳)并加錨鏈接

    vue2+wangEditor5富文本編輯器(圖片視頻上傳)并加錨鏈接

    官網(wǎng):https://www.wangeditor.com/v5/installation.html#npm 1、安裝使用 安裝 在main.js中引入樣式 在使用編輯器的頁(yè)面引入js 模板 js 到這一步編輯完就可以正常顯示了 2、上傳圖片、視頻 1)上傳到后臺(tái)接口的可直接按照文檔這個(gè)配置就行接口返回格式也要可文檔上一致 2)自定義上傳(一

    2024年02月12日
    瀏覽(93)
  • vue2+wangEditor5富文本編輯器(圖片視頻自定義上傳七牛云/服務(wù)器)

    vue2+wangEditor5富文本編輯器(圖片視頻自定義上傳七牛云/服務(wù)器)

    1、安裝使用 安裝 在main.js中引入樣式 在使用編輯器的頁(yè)面引入js 模板 js ?到這一步編輯器就可以正常顯示了 2、上傳圖片、視頻 上傳到后臺(tái)接口的可直接按照文檔這個(gè)配置就行接口返回格式也要可文檔上一致 ? ?2)自定義上傳(一般上傳到別的服務(wù)器上,我這邊是上傳到七

    2024年02月11日
    瀏覽(105)
  • Vue中使用 WangEditor 編輯器的詳細(xì)教程

    WangEditor 是一個(gè)基于 JavaScript 的富文本編輯器,提供了豐富的編輯功能和靈活的定制能力。以下是 WangEditor 的一些優(yōu)點(diǎn): 易于集成和使用 :WangEditor 提供了清晰的 API 和文檔,易于集成到各種前端項(xiàng)目中,無(wú)論是基于 Vue、React 還是其他框架。 功能豐富 :WangEditor 提供了豐富的

    2024年02月07日
    瀏覽(45)
  • wangEditor富文本編輯器圖片/視頻上傳

    wangEditor富文本編輯器圖片/視頻上傳

    wangEditor 有豐富的 API 和足夠的擴(kuò)展性,允許我們自定義開發(fā)菜單、模塊、插件等。在 Vue、React 中運(yùn)用也很方便。因此本文介紹下vue中富文本上傳圖片和視頻。 安裝引入后富文本有顯示上傳圖片按鈕,點(diǎn)擊上傳后會(huì)報(bào) 沒(méi)有配置上傳地址 的錯(cuò)誤,如下圖所示: 所以自定義上傳

    2024年02月15日
    瀏覽(95)
  • 文本編輯器Notepad++ 官方下載地址

    文本編輯器Notepad++ 官方下載地址

    1、官網(wǎng)下載 notepad++ 官網(wǎng)地址 https://notepad-plus-plus.org/ (但官網(wǎng)一直進(jìn)不去,可能是國(guó)內(nèi)將其封禁了) 所以如果點(diǎn)擊進(jìn)不去官網(wǎng)就請(qǐng)嘗試下面的方法。 2、Notepad++外網(wǎng)下載 地址如下:Notepad++ - Download (softonic.com) (親測(cè)可以下載~~~) ?

    2024年02月16日
    瀏覽(16)
  • Vue3項(xiàng)目中使用富文本編輯器

    tinymce簡(jiǎn)介 一、 安裝 二、使用步驟 1. 封裝組件 2. 組件中掛載 3.應(yīng)用富文本 總結(jié) TinyMCE 是一款易用、且功能強(qiáng)大的所見(jiàn)即所得的富文本編輯器。跟其他富文本編輯器相比,有著豐富的插件,支持多種語(yǔ)言,能夠滿足日常的業(yè)務(wù)需求并且免費(fèi)。 一、安裝Tinymce 注意:版本可根據(jù)

    2024年02月15日
    瀏覽(30)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包