vue-element-admin的安装以及安装报错处理
一、vue-element-admin git地址
https://github.com/PanJiaChen/vue-element-admin
二、分支
master:主分支,(纯英文)
il8n:中英文切换分支
三、npm install 安装报错原因: tui-editor 已更新,故造成错误,修改如下
四、 安装报错处理
1、修改package.json文件
将 "tui-editor": "1.3.3" 替换成 "@toast-ui/editor": "^3.1.3"
2、找到 src/components/MarkdownEditor/index.vue 文件修改代码
(1)将 import 'tui-editor/dist/tui-editor.css' 替换成 import '@toast-ui/editor/dist/toastui-editor.css'
(2)将 import Editor from 'tui-editor' 替换成 import Editor from '@toast-ui/editor'
(3)去掉 import 'tui-editor/dist/tui-editor-contents.css'
(4)将所有 editor.getValue 替换成 editor.getMarkdown
(5)将所有 editor.setValue 替换成 editor.setMarkdown
(6)将 editor.getHtml 替换成 editor.getHTML
修改完如下:
<template> <div :id="id" /> </template> <script> // deps for editor import 'codemirror/lib/codemirror.css' // codemirror import '@toast-ui/editor/dist/toastui-editor.css' // editor style import Editor from '@toast-ui/editor' import defaultOptions from './default-options' export default { name: 'MarkdownEditor', props: { value: { type: String, default: '' }, id: { type: String, required: false, default() { return 'markdown-editor-' + +new Date() + ((Math.random() * 1000).toFixed(0) + '') } }, options: { type: Object, default() { return defaultOptions } }, mode: { type: String, default: 'markdown' }, height: { type: String, required: false, default: '300px' }, language: { type: String, required: false, default: 'en_US' // https://github.com/nhnent/tui.editor/tree/master/src/js/langs } }, data() { return { editor: null } }, computed: { editorOptions() { const options = Object.assign({}, defaultOptions, this.options) options.initialEditType = this.mode options.height = this.height options.language = this.language return options } }, watch: { value(newValue, preValue) { if (newValue !== preValue && newValue !== this.editor.getMarkdown()) { this.editor.setMarkdown(newValue) } }, language(val) { this.destroyEditor() this.initEditor() }, height(newValue) { this.editor.height(newValue) }, mode(newValue) { this.editor.changeMode(newValue) } }, mounted() { this.initEditor() }, destroyed() { this.destroyEditor() }, methods: { initEditor() { this.editor = new Editor({ el: document.getElementById(this.id), ...this.editorOptions }) if (this.value) { this.editor.setMarkdown(this.value) } this.editor.on('change', () => { this.$emit('input', this.editor.getMarkdown()) }) this.editor.addHook('addImageBlobHook', (file, cb) => { if (typeof this.$listeners.uploadImageEvent === 'function') { this.$emit('uploadImageEvent', file, cb) } else { const reader = new FileReader() reader.onload = ({ target }) => { cb(target.result || '') } reader.readAsDataURL(file) } }) }, destroyEditor() { if (!this.editor) return this.editor.off('change') this.editor.destroy() }, setValue(value) { this.editor.setMarkdown(value) }, getValue() { return this.editor.getMarkdown() }, setHtml(value) { this.editor.setHTML(value) }, getHtml() { return this.editor.getHTML() } } } </script>
(7)将 同级 default-options.js修改如下
toolbarItems: [
'heading','bold','italic','strike','divider',
'hr','quote','divider',
'ul','ol','task','indent','outdent','divider',
'table','image','link','divider',
'code','codeblock'
]
替换成
toolbarItems: [
['heading', 'bold', 'italic', 'strike'],
['hr', 'quote'],
['ul', 'ol', 'task', 'indent', 'outdent'],
['table', 'image', 'link'],
['code', 'codeblock']
]
(8)将 src/views/components-demo/markdown.vue 文件中
'heading','bold','italic'
替换成
['heading','bold','italic']
(9) 将 editor.remove() 替换成 editor.destroy()
之后,重新安装依赖,启动项目即可正常运行
https://zhuanlan.zhihu.com/p/503839146
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律