博客 分类专栏 专题 成员
Vue3 prototype使用
2022-05-29 01:27:03
分类专栏: Vue3

Vue3 prototype使用

Vue2.x 中使用

先说 Vue2.x 中我们可以直接派生vue对象
比如
在main.js中配置

Vue.prototype.$echarts = echarts

然后使用就直接 this.$echarts 就可以了

Vue3.x 中使用

在main.js中配置

const app = createApp(App)
app.config.globalProperties.$echarts= echarts
app.use(router)
app.mount('#app')

申明式 Api 使用

就是跟vue2一样的 使用 data() methods 这样的,用法就跟vue2一样直接this.$echats

组合式Api

import {  getCurrentInstance } from 'vue'
export default {
    setup () {
        let { proxy } = getCurrentInstance();
        // 这样使用 proxy.$echarts
        return {

        }
    }
}