vue3 全局属性配置-mian

一.初始化

以前vue2 书写形式

import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store/store'
 new Vue({
    router,
    store,
    render: h => h(App)
  }).$mount('#app')
 

 

vue3写法

import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'

createApp(App).use(store).use(router).mount('#app')

 

全局属性配置

vue2

Vue.prototype.$request = request
Vue.config.errorHandler = errorHandler

 

vue3

config属性不变,

prototype改成config

然后添加 globalProperties

let app = createApp(App)
app.config.globalProperties.errorHandler = errorHandler
  app.config.globalProperties.$request = request

 

三,全局事件总线

vue2

Vue.prototype.$eventBus = new Vue({})

 

 
vue3
let app = createApp(App)
app.config.globalProperties.$eventBus = createApp({})

 

参考链接https://blog.csdn.net/weixin_43520044/article/details/109284503

posted @ 2022-04-27 10:39  树叶铃铛  阅读(753)  评论(0编辑  收藏  举报