vue2.5入口文件配置全局属性
- Vue 2.0之前我们封装axios和message等通用属性的时候是这么写的:
import Vue from "vue";
import echarts from "echarts";
Vue.prototype.$echarts = echarts
- 然后在组件内使用 this.$echarts就可以调用了,但是Vue3更新了以后这样写会报错
vue3入口文件配置全局属性
const app=createApp(App);
app.use(store);
app.use(router);
app.mount('#app');
// 配置全局属性
app.config.globalProperties.$echarts = echarts;
- vue3获取vue实例
import { getCurrentInstance } from 'vue'
let $this = getCurrentInstance().appContext.config.globalProperties;
console($this.$echarts)