vue-element-admin 二次开发 报错修改

安装

GitHub:

git clone https://github.com/PanJiaChen/vue-element-admin.git

Gitee:

https://gitee.com/panjiachen/vue-element-admin.git

npm install 或者 cnpm install(建议)

Install fail! Error: [[email protected][email protected] › raphael@git+https://github.com/nhn/raphael.git#2.2.0-c] An unknown git error occurred
在这里插入图片描述

解决方法

1.报错先删除package.json里的tui-editor
2.采用@toast-ui/editor库

(1) 安装@toast-ui/editor包: npm install @toast-ui/editor --save
(2) 修改 src/components/MarkdownEditor/index.vue 

具体修改如下:

<template>
  <div :id="id" />
template>

<script>
// deps for editor
// import 'codemirror/lib/codemirror.css' // codemirror
// import 'tui-editor/dist/tui-editor.css' // editor ui
// import 'tui-editor/dist/tui-editor-contents.css' // editor content
import 'codemirror/lib/codemirror.css'// Editor's Dependency Style
import '@toast-ui/editor/dist/toastui-editor.css'// Editor's Style
// import Editor from 'tui-editor'
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())
      })
    },
    destroyEditor() {
      if (!this.editor) return
      this.editor.off('change')
      this.editor.remove()
    },
    setValue(value) {
      this.editor.setMarkdown(value)
    },
    getValue() {
      return this.editor.getMarkdown()
    },
    setHtml(value) {
      this.editor.setHtml(value)
    },
    getHtml() {
      return this.editor.getHtml()
    }
  }
}
script>

在这里插入图片描述
报错 Cannot find module ‘body-parser’

/mock/mock-server.js 注释掉红圈里的内容

vue-element-admin 二次开发 报错修改_第1张图片
vue-element-admin 二次开发 报错修改_第2张图片

core报错解决方法:

第一步:删除node_modules
第二步: 独立安装(core-js)  
sudo cnpm install --save core-js
第三步:安装其他依赖
sudo cnpm i
第四步:运行
npm run serve

你可能感兴趣的:(vue.js,前端)