vue2.0使用md-edit編輯器的過程
前言:小劉開發(fā)過程中,如果是博客項(xiàng)目一般是會(huì)用到富文本。眾多富文本中,小劉選擇了markdown,并記錄分享了下來。
# 使用 npm
npm i @kangc/v-md-editor -S
main.js基本配置
import VueMarkdownEditor from '@kangc/v-md-editor';
import '@kangc/v-md-editor/lib/style/base-editor.css';
import vuepressTheme from '@kangc/v-md-editor/lib/theme/vuepress.js';
import '@kangc/v-md-editor/lib/theme/style/vuepress.css';
import Prism from 'prismjs';
VueMarkdownEditor.use(vuepressTheme, {
Prism,
});
/* 2、v-md-editor 代碼塊關(guān)鍵字高亮 */
import githubTheme from '@kangc/v-md-editor/lib/theme/github.js';
import '@kangc/v-md-editor/lib/theme/style/github.css';
// 引入所有語言包
import hljs from 'highlight.js';
VueMarkdownEditor.use(githubTheme, {
Hljs: hljs,
});
/**
* 3.創(chuàng)建行號
*/
import createLineNumbertPlugin from '@kangc/v-md-editor/lib/plugins/line-number/index';
VueMarkdownEditor.use(createLineNumbertPlugin());
Vue.use(VueMarkdownEditor);頁面加載使用
<template>
<div class="hello">
<v-md-editor v-model="text" height="400px"></v-md-editor>
</div>
</template>
<script>
export default {
data() {
return {
text: '',
};
},
};
</script>特別注意:當(dāng)步驟到行號的時(shí)候,會(huì)出現(xiàn)依賴有問題;
類似:* @babel/runtime/helpers/interopRequireDefault in ./node_modules/@kangc/v-md-editor/lib/plugins/line-number/index.js To install it, you can run: npm install --save @babel/runtime/helpers/interopRequireDefault Error from chokidar (C:): Error: EBUSY: reso。。。。。。。
這種錯(cuò)誤;
解決方案:
當(dāng)使用 babel 轉(zhuǎn)換 es 6出現(xiàn)下面錯(cuò)誤時(shí):
Module not found: Error: Can’t resolve
‘@babel/runtime/helpers/interopRequireDefault’ 我們可以重新安裝一下:npm i @babel/runtime --save-dev
至此:github主題的markdown編輯器基本用法完成了。
運(yùn)行demo效果:

圖片上傳功能:將圖片上傳到服務(wù)器,然后回顯圖片
:disabled-menus="[]" @upload-image="handleUploadImage"
注意
上傳圖片菜單默認(rèn)為禁用狀態(tài) 設(shè)置 disabled-menus 為空數(shù)組可以開啟。
handleUploadImage(event, insertImage, files) {
// 拿到 files 之后上傳到文件服務(wù)器,然后向編輯框中插入對應(yīng)的內(nèi)容
console.log(files);
// 此處只做示例
insertImage({
url:
'https://pic.rmb.bdstatic.com/bjh/down/a477f2b15e2039b9fc7e2282791a9897.jpeg',
desc: '七龍珠',
// width: 'auto',
// height: 'auto',
});
},測試效果如下

到此這篇關(guān)于vue2.0+使用md-edit編輯器的文章就介紹到這了,更多相關(guān)vue2.0使用md-edit編輯器內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- Vue3?使用v-md-editor如何動(dòng)態(tài)上傳圖片的方法實(shí)現(xiàn)
- vue-quill-editor富文本編輯器上傳視頻功能詳解
- vue使用富文本編輯器vue-quill-editor的操作指南和注意事項(xiàng)
- VUE3使用JSON編輯器的詳細(xì)圖文教程
- vue中wangEditor5編輯器的基本使用
- uni-app 使用編輯器創(chuàng)建vue3 項(xiàng)目并且運(yùn)行的操作方法
- Vue如何整合mavon-editor編輯器(markdown編輯和預(yù)覽)
- vue-json-editor json編輯器的使用
- Vue 實(shí)現(xiàn)可視化拖拽頁面編輯器
相關(guān)文章
element-ui 遠(yuǎn)程搜索組件el-select在項(xiàng)目中組件化的實(shí)現(xiàn)代碼
這篇文章主要介紹了element-ui 遠(yuǎn)程搜索組件el-select在項(xiàng)目中組件化,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-12-12
Vue2中實(shí)現(xiàn)輸入中文自動(dòng)轉(zhuǎn)化為拼音且不帶音調(diào)的實(shí)現(xiàn)方案
文章介紹了在Vue2中實(shí)現(xiàn)輸入中文自動(dòng)轉(zhuǎn)化為拼音且不帶音調(diào)的幾種方案,包括使用pinyin庫、自定義指令、計(jì)算屬性、帶防抖的優(yōu)化版本以及使用其他拼音庫,推薦使用方案一和方案三,因其實(shí)現(xiàn)簡單且易于維護(hù),感興趣的朋友跟隨小編一起看看吧2025-12-12
在Vuex使用dispatch和commit來調(diào)用mutations的區(qū)別詳解
今天小編就為大家分享一篇在Vuex使用dispatch和commit來調(diào)用mutations的區(qū)別詳解,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-09-09
Vite結(jié)合Vue刪除指定環(huán)境的console.log問題
這篇文章主要介紹了Vite結(jié)合Vue刪除指定環(huán)境的console.log問題,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-03-03
vue + element-ui的分頁問題實(shí)現(xiàn)
這篇文章主要介紹了vue + element-ui的分頁問題實(shí)現(xiàn),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-12-12
vue3?hook重構(gòu)DataV的全屏容器組件詳解
這篇文章主要為大家介紹了vue3?hook重構(gòu)DataV的全屏容器組件詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-04-04
Vue3 根據(jù)路由動(dòng)態(tài)生成側(cè)邊菜單的方法
本文介紹了如何在Vue3項(xiàng)目中根據(jù)路由動(dòng)態(tài)生成側(cè)邊菜單,包括準(zhǔn)備工作、路由配置基礎(chǔ)、組件搭建和優(yōu)化與拓展,通過這些步驟,可以實(shí)現(xiàn)一個(gè)靈活且可擴(kuò)展的側(cè)邊菜單系統(tǒng),提升用戶體驗(yàn),感興趣的朋友一起看看吧2025-01-01
解決vue項(xiàng)目中頁面調(diào)用數(shù)據(jù) 在數(shù)據(jù)加載完畢之前出現(xiàn)undefined問題
今天小編就為大家分享一篇解決vue項(xiàng)目中頁面調(diào)用數(shù)據(jù) 在數(shù)據(jù)加載完畢之前出現(xiàn)undefined問題,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-11-11
iView-admin 動(dòng)態(tài)路由問題的解決方法
這篇文章主要介紹了iView-admin 動(dòng)態(tài)路由問題的解決方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-10-10

