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)建行號(hào) */ 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)步驟到行號(hào)的時(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ù)器,然后向編輯框中插入對(duì)應(yīng)的內(nèi)容 console.log(files); // 此處只做示例 insertImage({ url: 'https://pic.rmb.bdstatic.com/bjh/down/a477f2b15e2039b9fc7e2282791a9897.jpeg', desc: '七龍珠', // width: 'auto', // height: 'auto', }); },
測(cè)試效果如下
到此這篇關(guān)于vue2.0+使用md-edit編輯器的文章就介紹到這了,更多相關(guān)vue2.0使用md-edit編輯器內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(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)文章
Vue PC端實(shí)現(xiàn)掃碼登錄功能示例代碼
目前大多數(shù)PC端應(yīng)用都有配套的移動(dòng)端APP,如微信,淘寶等,通過使用手機(jī)APP上的掃一掃功能去掃頁面二維碼圖片進(jìn)行登錄,使得用戶登錄操作更方便,安全,快捷,這篇文章主要介紹了Vue PC端如何實(shí)現(xiàn)掃碼登錄功能,需要的朋友可以參考下2023-01-01Vue.js?rules校驗(yàn)規(guī)則舉例詳解
Vue表單校驗(yàn)規(guī)則(rules)是一種用于驗(yàn)證表單數(shù)據(jù)的對(duì)象,它通常用于Vue.js框架中的表單組件中,可以在表單提交前進(jìn)行數(shù)據(jù)驗(yàn)證,這篇文章主要給大家介紹了關(guān)于Vue.js?rules校驗(yàn)規(guī)則的相關(guān)資料,需要的朋友可以參考下2024-02-02springboot和vue前后端交互的實(shí)現(xiàn)示例
本文主要介紹了springboot和vue前后端交互的實(shí)現(xiàn)示例,將包括一個(gè)簡(jiǎn)單的Vue.js前端應(yīng)用程序,用于發(fā)送GET請(qǐng)求到一個(gè)Spring Boot后端應(yīng)用程序,以獲取并顯示用戶列表,感興趣的可以了解一下2024-05-05Vue.js每天必學(xué)之?dāng)?shù)據(jù)雙向綁定
Vue.js每天必學(xué)之?dāng)?shù)據(jù)雙向綁定,如何進(jìn)行綁定,如何進(jìn)行數(shù)據(jù)雙向綁定,感興趣的小伙伴們可以參考一下2016-09-09vue cli3.0打包上線靜態(tài)資源找不到路徑的解決操作
這篇文章主要介紹了vue cli3.0打包上線靜態(tài)資源找不到路徑的解決操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-08-08Vue實(shí)現(xiàn)上拉加載下一頁效果的示例代碼
這篇文章主要為大家詳細(xì)介紹了如何利用Vue實(shí)現(xiàn)上拉加載下一頁效果,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)Vue有一定幫助,需要的可以參考一下2022-08-08