Vue2 的全局配置
import Vue from ‘vue‘
import App from ‘./App.vue‘
Vue.config.ignoredElements = [/^app-/]
Vue.use(/* ... */)
Vue.mixin(/* ... */)
Vue.component(/* ... */)
Vue.directive(/* ... */)
Vue.prototype.customProperty = () => {}
new Vue({
render: h => h(App)
}).$mount(‘#app‘)
Vue2 这样写在一定程度上修改了 Vue 对象的全局状态。
Vue3 的修改
import { createApp } from ‘vue‘
import App from ‘./App.vue‘
const app = createApp(App)
// 这个时候 app 就是一个 App 的实例,现在再设置任何的配置是在不同的 app 实例上面的,不会像vue2 一样发生任何的冲突。
app.config.isCustomElement = tag => tag.startsWith(‘app-‘)
app.use(/* ... */)
app.mixin(/* ... */)
app.component(/* ... */)
app.directive(/* ... */)
app.config.globalProperties.customProperty = () => {}
// 当配置结束以后,我们再把 App 使用 mount 方法挂载到固定的 DOM 的节点上。
app.mount(App, ‘#app‘)
原文:https://www.cnblogs.com/duet/p/14460330.html