vue ts 富文本編輯器 整理

引言

因公司項(xiàng)目憾朴,需要找到一個(gè)VUE+Ts+Nuxt 的富文本編輯器事格,需要可改圖標(biāo),可配置國(guó)際化玄帕,可配置工具欄,不能出現(xiàn)中文

vue2-editor

支持ts 支持VUE 支持配置工具欄 暫不支持換圖標(biāo)

安裝語(yǔ)句

npm install vue2-editor
npm i --save-dev @types/vue2-editor

使用

import { VueEditor } from "vue2-editor";
<vue-editor v-model="content" :editorToolbar="customToolbar"></vue-editor>

配置工具欄

其中沒(méi)有官方文檔講有哪些配置名字想邦,最后通過(guò)翻node_moudles中找到默認(rèn)全部配置如下

defaultToolbar = 
[
  [{header: [false, 1, 2, 3, 4, 5, 6]}],
  ["bold", "italic", "underline", "strike"], // toggled buttons
  [{align: ""}, { align: "center"}, {align: "right"}, {align: "justify"}],
  ["blockquote", "code-block"],
  [{list: "ordered"}, {list: "bullet"}, {list: "check"}], 
  [{indent: "-1"}, {indent: "+1"}], // outdent/indent
  [{color: []}, {background: []}], // dropdown with defaults from theme
  ["link", "image", "video"], ["clean"] // remove formatting button
];

wangeditor

支持Ts 支持 Vue 支持 nuxt 支持配置工具欄 支持換圖標(biāo) ?阄啤!案狠!這貨國(guó)際化竟然是中文為key

安裝

npm i wangeditor
npm i --save-dev @types/wangeditor

使用

import E from 'wangeditor';

<div id="editor"></div>

const editor = new E('#editor');
editor.config.uploadImgServer = '/upload-img';
        editor.config.onchange = (html: any) => {
            this.getFullText(html);
        };
        editor.config.showLinkImg = true;
        editor.config.height = 119;
        editor.config.uploadImgServer = editor1.config.uploadFileName = 'file';
        editor.config.zIndex = 8;
        editor.config.uploadImgParams = {
            from: 'editor'
        };
        editor.create();
        if (this.content) {
            editor1.txt.html(this.content);
        }

配置相關(guān)

請(qǐng)自己百度或bing一下wangeditor服傍,有文檔的

vue-froala-wysiwyg

不支持Ts

安裝

npm install vue-froala-wysiwyg --save

詳情

https://github.com/froala/vue-froala-wysiwyg

vue-wysiwyg

不支持Ts

安裝

npm install vue-wysiwyg --save

詳情

https://github.com/chmln/vue-wysiwyg

vue-html5-editor

不支持Ts 但是這個(gè)其他方面感覺(jué)挺齊全的

安裝

npm install vue-html5-editor --save

詳情

https://github.com/PeakTai/vue-html5-editor

Vue-Quill-Editor

不支持Ts 但是這個(gè)富文本要是不用ts的話(huà)還是可以的 文檔齊全

安裝

npm install vue-quill-editor --save

詳情

https://github.com/surmon-china/vue-quill-editor

SunEditor

支持 vue 支持 ts 可配置圖標(biāo) 就是和UI出入太大

安裝

npm install suneditor --save

使用

<textarea id="sample">Hi</textarea>

import 'suneditor/dist/css/suneditor.min.css'
import suneditor from 'suneditor'
import plugins from 'suneditor/src/plugins'

suneditor.create('sample', {
    plugins: plugins,
    buttonList: [
        ['undo', 'redo'],
        ['font', 'fontSize', 'formatBlock'],
        ['paragraphStyle', 'blockquote'],
        ['bold', 'underline', 'italic', 'strike', 'subscript', 'superscript'],
        ['fontColor', 'hiliteColor', 'textStyle'],
        ['removeFormat'],
        '/', // Line break
        ['outdent', 'indent'],
        ['align', 'horizontalRule', 'list', 'lineHeight'],
        ['table', 'link', 'image', 'video', 'audio' /** ,'math' */], // You must add the 'katex' library at options to use the 'math' plugin.
        /** ['imageGallery'] */ // You must add the "imageGalleryUrl".
        ['fullScreen', 'showBlocks', 'codeView'],
        ['preview', 'print'],
        ['save', 'template']
    ]
})

評(píng)價(jià)

UI出入太大了,但是實(shí)現(xiàn)極快骂铁,所見(jiàn)即所得吹零,花里胡哨的圖片功能

Quill

目前基本全方位滿(mǎn)足

安裝

npm install quill
npm i --save-dev @types/quill

使用

<template>
    <div>
        <div class="editor"></div>
    </div>
</template>

<script lang="ts">
/* eslint-disable camelcase */
/* eslint-disable no-unused-expressions */
/* eslint-disable @typescript-eslint/no-empty-function */
import { Component, Vue, Prop, Emit } from 'vue-property-decorator';
import Quill from 'quill';
import 'quill/dist/quill.snow.css';

@Component({ name: 'TinymceEditer', components: {} })
export default class extends Vue {
    @Prop({ type: String, default: '', required: false })
    private value: any;
    @Emit('getParams')
    emitTodo(params: any): number {
        return params;
    }
    quill = null;
    options = {
        theme: 'snow',
        modules: {
            toolbar: [
                ['bold', 'italic', 'underline', 'strike'],
                ['blockquote', 'code-block'],
                [{ header: 1 }, { header: 2 }],
                [{ list: 'ordered' }, { list: 'bullet' }],
                [{ script: 'sub' }, { script: 'super' }],
                [{ indent: '-1' }, { indent: '+1' }],
                [{ direction: 'rtl' }],
                [{ size: ['small', false, 'large', 'huge'] }],
                [{ header: [1, 2, 3, 4, 5, 6, false] }],
                [{ color: [] }, { background: [] }],
                [{ font: [] }],
                [{ align: [] }],
                ['clean'],
                ['link', 'image', 'video']
            ]
        },
        placeholder: 'Insert text here ...'
    };
    mounted() {
        let dom = this.$el.querySelector('.editor');

        (this.quill as any) = new Quill(dom as Element, this.options);

        (this.quill as any).setContents(this.value);

        (this.quill as any).on('text-change', () => {
            this.emitTodo((this.quill as any).getContents());
        });
    }
}
</script>

<style lang="scss">
</style>

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市拉庵,隨后出現(xiàn)的幾起案子灿椅,更是在濱河造成了極大的恐慌,老刑警劉巖钞支,帶你破解...
    沈念sama閱讀 211,376評(píng)論 6 491
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件茫蛹,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡烁挟,警方通過(guò)查閱死者的電腦和手機(jī)婴洼,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,126評(píng)論 2 385
  • 文/潘曉璐 我一進(jìn)店門(mén),熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)撼嗓,“玉大人柬采,你說(shuō)我怎么就攤上這事∏揖” “怎么了粉捻?”我有些...
    開(kāi)封第一講書(shū)人閱讀 156,966評(píng)論 0 347
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)斑芜。 經(jīng)常有香客問(wèn)我肩刃,道長(zhǎng),這世上最難降的妖魔是什么? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 56,432評(píng)論 1 283
  • 正文 為了忘掉前任盈包,我火速辦了婚禮沸呐,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘续语。我一直安慰自己垂谢,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,519評(píng)論 6 385
  • 文/花漫 我一把揭開(kāi)白布疮茄。 她就那樣靜靜地躺著滥朱,像睡著了一般。 火紅的嫁衣襯著肌膚如雪力试。 梳的紋絲不亂的頭發(fā)上徙邻,一...
    開(kāi)封第一講書(shū)人閱讀 49,792評(píng)論 1 290
  • 那天,我揣著相機(jī)與錄音畸裳,去河邊找鬼缰犁。 笑死,一個(gè)胖子當(dāng)著我的面吹牛怖糊,可吹牛的內(nèi)容都是我干的帅容。 我是一名探鬼主播,決...
    沈念sama閱讀 38,933評(píng)論 3 406
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼伍伤,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼并徘!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起扰魂,我...
    開(kāi)封第一講書(shū)人閱讀 37,701評(píng)論 0 266
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤麦乞,失蹤者是張志新(化名)和其女友劉穎,沒(méi)想到半個(gè)月后劝评,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體姐直,經(jīng)...
    沈念sama閱讀 44,143評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,488評(píng)論 2 327
  • 正文 我和宋清朗相戀三年蒋畜,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了声畏。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 38,626評(píng)論 1 340
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡姻成,死狀恐怖插龄,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情佣渴,我是刑警寧澤,帶...
    沈念sama閱讀 34,292評(píng)論 4 329
  • 正文 年R本政府宣布初斑,位于F島的核電站辛润,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜砂竖,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,896評(píng)論 3 313
  • 文/蒙蒙 一真椿、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧乎澄,春花似錦突硝、人聲如沸。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 30,742評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至浙于,卻和暖如春护盈,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背羞酗。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 31,977評(píng)論 1 265
  • 我被黑心中介騙來(lái)泰國(guó)打工腐宋, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人檀轨。 一個(gè)月前我還...
    沈念sama閱讀 46,324評(píng)論 2 360
  • 正文 我出身青樓胸竞,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親参萄。 傳聞我的和親對(duì)象是個(gè)殘疾皇子卫枝,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,494評(píng)論 2 348

推薦閱讀更多精彩內(nèi)容