vue2.0使用md-edit編輯器的過程
前言:小劉開發(fā)過程中,如果是博客項目一般是會用到富文本。眾多富文本中,小劉選擇了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>特別注意:當步驟到行號的時候,會出現(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。。。。。。。
這種錯誤;
解決方案:
當使用 babel 轉(zhuǎn)換 es 6出現(xiàn)下面錯誤時:
Module not found: Error: Can’t resolve
‘@babel/runtime/helpers/interopRequireDefault’ 我們可以重新安裝一下:npm i @babel/runtime --save-dev
至此:github主題的markdown編輯器基本用法完成了。
運行demo效果:

圖片上傳功能:將圖片上傳到服務器,然后回顯圖片
:disabled-menus="[]" @upload-image="handleUploadImage"
注意
上傳圖片菜單默認為禁用狀態(tài) 設置 disabled-menus 為空數(shù)組可以開啟。
handleUploadImage(event, insertImage, files) {
// 拿到 files 之后上傳到文件服務器,然后向編輯框中插入對應的內(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)文章希望大家以后多多支持腳本之家!
相關(guān)文章
element-ui 遠程搜索組件el-select在項目中組件化的實現(xiàn)代碼
這篇文章主要介紹了element-ui 遠程搜索組件el-select在項目中組件化,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-12-12
Vue2中實現(xiàn)輸入中文自動轉(zhuǎn)化為拼音且不帶音調(diào)的實現(xiàn)方案
文章介紹了在Vue2中實現(xiàn)輸入中文自動轉(zhuǎn)化為拼音且不帶音調(diào)的幾種方案,包括使用pinyin庫、自定義指令、計算屬性、帶防抖的優(yōu)化版本以及使用其他拼音庫,推薦使用方案一和方案三,因其實現(xiàn)簡單且易于維護,感興趣的朋友跟隨小編一起看看吧2025-12-12
在Vuex使用dispatch和commit來調(diào)用mutations的區(qū)別詳解
今天小編就為大家分享一篇在Vuex使用dispatch和commit來調(diào)用mutations的區(qū)別詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-09-09
Vite結(jié)合Vue刪除指定環(huán)境的console.log問題
這篇文章主要介紹了Vite結(jié)合Vue刪除指定環(huán)境的console.log問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-03-03
vue3?hook重構(gòu)DataV的全屏容器組件詳解
這篇文章主要為大家介紹了vue3?hook重構(gòu)DataV的全屏容器組件詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-04-04
Vue3 根據(jù)路由動態(tài)生成側(cè)邊菜單的方法
本文介紹了如何在Vue3項目中根據(jù)路由動態(tài)生成側(cè)邊菜單,包括準備工作、路由配置基礎、組件搭建和優(yōu)化與拓展,通過這些步驟,可以實現(xiàn)一個靈活且可擴展的側(cè)邊菜單系統(tǒng),提升用戶體驗,感興趣的朋友一起看看吧2025-01-01
解決vue項目中頁面調(diào)用數(shù)據(jù) 在數(shù)據(jù)加載完畢之前出現(xiàn)undefined問題
今天小編就為大家分享一篇解決vue項目中頁面調(diào)用數(shù)據(jù) 在數(shù)據(jù)加載完畢之前出現(xiàn)undefined問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-11-11

