hinesboy / mavonEditor

mavonEditor - A markdown editor based on Vue that supports a variety of personalized features
http://www.mavoneditor.com/
MIT License
6.4k stars 917 forks source link

How to use in vue3 + vite? #736

Open catacode opened 2 years ago

catacode commented 2 years ago

Can you provide a case of vue3? I have try use mavonEditor under the syntax of vue3, But it failed。

Please give me a sample to depend!

![Uploading image.png…]()

ygj6 commented 2 years ago

Vue3 version of mavon-editor should be installed: npm i mavon-editor@3.0.0-beta

Usage:

    // 全局注册
    // import with ES6
    import { createApp } from 'vue'
    import mavonEditor from 'mavon-editor'
    import 'mavon-editor/dist/css/index.css'
    // use
    createApp(App).use(mavonEditor).mount('#app')

Reference Documents: https://github.com/originjs/mavonEditor-next#use-%E5%A6%82%E4%BD%95%E5%BC%95%E5%85%A5

catacode commented 2 years ago

Thank you very much, It's done.

  1. first install dependencies npm i mavon-editor@3.0.0-beta

  2. vue code

    
    <template>
    <h1>mavo editor</h1>
    <div id="mavon-editor-id">
    <mavon-editor v-model="editor_value" />
    </div>
    </template>
barbirict commented 1 year ago

Hi, I would just like to add this here, in case anyone is trying to use this editor with Vite SSR, since if you import it normally you'll get window not definded errors.

Code:

import { definePlugin } from '/@src/app'
// @ts-ignore
import { defineAsyncComponent } from 'vue'

export default definePlugin(({ app }) => {
  app.component(
    'mavon-editor',
    defineAsyncComponent({
      // @ts-ignore
      loader: () =>
        import('mavon-editor').then(
          (mod) => mod.mavonEditor
        ),
    })
  )
})