Skip to content

Latest commit

 

History

History
144 lines (106 loc) · 3.25 KB

README.md

File metadata and controls

144 lines (106 loc) · 3.25 KB

vue-mount-plugin

A simple and easy to use vue instance extension plugin that supports vue2.0 and vue3.0

NPM version Codacy Badge Test coverage npm download License

Sonar

For API documentation, see: API Docs

Installing

# use pnpm
$ pnpm install vue-mount-plugin

# use npm
$ npm install vue-mount-plugin --save

# use yarn
$ yarn add vue-mount-plugin

Usage

Use in Vue >=3.0

<template>
  <div></div>
</template>

<script setup>
import { getCurrentInstance } from 'vue'
import Mount from 'vue-mount-plugin'
import DemoVue from './demo.vue'

const { proxy } = getCurrentInstance()
const instance = new Mount(DemoVue, { parent: proxy.$root })

// mount to the end of document.body
instance.mount()

// destroy
instance.destroy()
</script>

Use in Vue 2.7

<template>
  <div></div>
</template>

<script>
import { getCurrentInstance } from 'vue'
import Mount from 'vue-mount-plugin'
import DemoVue from './demo.vue'

export default {
  setup() {
    const { proxy } = getCurrentInstance()
    const instance = new Mount(DemoVue, { parent: proxy.$root })

    // mount to the end of document.body
    instance.mount()

    // destroy
    instance.destroy()
  }
}
</script>

Use in Vue <=2.6

Add @vue/composition-api to the project.json dependencies and run install.

{
  "dependencies": {
    "@vue/composition-api": "latest"
  }
}
<template>
  <div></div>
</template>

<script>
import { getCurrentInstance } from '@vue/composition-api'
import Mount from 'vue-mount-plugin'
import DemoVue from './demo.vue'

export default {
  setup() {
    const { proxy } = getCurrentInstance()
    const instance = new Mount(DemoVue, { parent: proxy.$root })

    // mount to the end of document.body
    instance.mount()

    // destroy
    instance.destroy()
  }
}
</script>

Support & Issues

Please open an issue here.

License

MIT