首页 > 其他分享 >vue-element-admin的安装以及安装报错处理

vue-element-admin的安装以及安装报错处理

时间:2023-08-09 09:34:29浏览次数:33  
标签:vue default 替换成 tui 报错 editor import 安装 options

一、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

标签:vue,default,替换成,tui,报错,editor,import,安装,options
From: https://www.cnblogs.com/-roc/p/17615994.html

相关文章

  • Vue3+ElementPlus,Cannot read properties of null (reading 'isCE')
    一、环境vue3,ElementPlus,@vue/cli5.0.8,npm9.6.7。二、报错内容在vue3框架,views文件夹下的AboutView.vue文件里,执行<el-button>Default</el-button>语句就会报错如下:Uncaughtruntimeerrors:×ERRORCannotreadpropertiesofnull(reading'isCE')TypeError:Cannotread......
  • Linux中PXE高效批量网络装机和无人值守安装
    1、PXE1.1什么是PXEPXE是由lntel公司开发的网络引导技术,工作在CIient/Server模式,允许客户机通过网络从远程服务器下载引导镜像,并加载安装文件或者整个操作系统。PXE严格来说并不是一种安装方式,而是一种引导的方式。进行PXE安装的必要条性是要安装的计算机中包含个PXE......
  • 第六节:框架版本升级和Vuex改造为Pinia
    一.        二.        三.         !作       者:Yaopengfei(姚鹏飞)博客地址:http://www.cnblogs.com/yaopengfei/声     明1:如有错误,欢迎讨论,请勿谩骂^_^。声     明2:原创博客请在转载......
  • EFK家族---CentOS7安装Elasticsearch6.4.3和使用
    安装Elastic需要Java8环境。如果你的机器还没安装Java,可以参考这篇文章,注意要保证环境变量JAVA_HOME正确设置。linux软件(一)—CentOS安装jdk安装完Java,就可以跟着官方文档安装Elastic。直接下载压缩包比较简单。$wgethttps://artifacts.elastic.co/downloads/elasticsea......
  • 数据挖掘(五) -----基于Spark的可伸缩基因数据分析平台开源存储运算架构hail全面了解
    hail简介hail是一个开源的、通用的、面向python数据类型的处理基因数据专用的分析库和方法解决方案。hail的存在是为了支持多维度的复杂的数据结构,比如全基因组关联数据研究(GWAS).GWASTutorialhail的底层是通过python,scala,java和apachespark来实现的。hail官网gitlab官方文......
  • 【随手记】Mybatis报错 错误信息:ORA-00911: 无效字符
    注意@param注解是属于哪个包的这个有的时候会有影响接收不到参数xml里面不要加分号查了半天Bug最后发现是xml里面的sql语句后面加了个;,删掉就好了。......
  • vue--day58---多个元素过度
    1.App.vue<template> <div><Test></Test><Test2></Test2></div>  </template> <script> importTestfrom'./components/Test.vue';importTest2from'./components/Test2.vue';......
  • Docker学习(二)-----Docker安装和使用
    本章我们就来学习docker的安装和初步使用。LinuxCentOSDocker安装Docker支持以下的CentOS版本:CentOS7(64-bit)CentOS6.5(64-bit)或更高的版本前提条件目前,CentOS仅发行版本中的内核支持Docker。Docker运行在CentOS7上,要求系统为64位、系统内核版本为3.10以上......
  • 手动安装ceph和使用
    我们已经对ceph有了一个大概的了解,现在就进行手动的安装ceph集群。在我们安装集群之前,首先应该对自己的服务器环境以及集群节点作用做一个规划。架构设计Ceph分布式存储集群有三大组件组成,分为:CephMonitor、CephOSD、CephMDS,后边使用对象存储和块存储时,MDS非必须安装,只有当使......
  • Ansible的安装和全面介绍
    Ansible简介官网https://www.ansible.com/Ansible介绍视频https://www.youtube.com/watch?v=iVWmbStE1MMAnsible中文权威指南http://ansible-tran.readthedocs.io/en/latest/Ansible自动化运维教程https://www.w3cschool.cn/automate_with_ansible/官方的title是“AnsibleisS......