code-farmer-i / vue-markdown-editor

A markdown editor built on Vue
https://code-farmer-i.github.io/vue-markdown-editor/
MIT License
1.07k stars 110 forks source link

报错:The command name is already in use: tip #197

Open ZeronoFreya opened 1 year ago

ZeronoFreya commented 1 year ago

The command name is already in use: tip base-editor.js:3899

vue3 vite2

当组件使用v-if动态显示时出现

import VMdEditor 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 createLineNumbertPlugin from "@kangc/v-md-editor/lib/plugins/line-number/index";

import createCopyCodePlugin from "@kangc/v-md-editor/lib/plugins/copy-code/index";
import "@kangc/v-md-editor/lib/plugins/copy-code/copy-code.css";

import Prism from "prismjs";
import "prismjs/components/prism-json";

VMdEditor.use(vuepressTheme, {
    Prism,
});

VMdEditor.use(createLineNumbertPlugin());
VMdEditor.use(createCopyCodePlugin());

这个怎么解决呢?

popdo commented 1 year ago

同样遇到该问题

schneefux commented 1 year ago

I had the same issue when I tried to import VMdEditor locally.

What worked for me was to move the configuration to an external file ~/md-editor.js:

import '@kangc/v-md-editor/lib/style/base-editor.css'
import createEmojiPlugin from '@kangc/v-md-editor/lib/plugins/emoji/index'
import '@kangc/v-md-editor/lib/plugins/emoji/emoji.css'
import VMdEditor, { xss } from '@kangc/v-md-editor'

VMdEditor.use(createEmojiPlugin())

export default VMdEditor

Then you can import VMdEditor from '~/md-editor' without any errors because the plugins will only be registered once.

tgy3300 commented 1 year ago

我有个更好的办法,把下面这三行干掉 import createTipPlugin from '@kangc/v-md-editor/lib/plugins/tip/index' import '@kangc/v-md-editor/lib/plugins/tip/tip.css'

TextareaEditor.use(createTipPlugin())

然后,直接在toolbar引入tip,就行了,这个错误应该是重复注册了