以前(Vue2.x)
import Vue from \'vue\'import App from \'./App.vue\'
Vue.config.ignoredElements = [/^app-/]
Vue.use(/* ... */)
Vue.mixin(/* ... */)
Vue.component(/* ... */)
Vue.directive(/* ... */)
new Vue({
render: h => h(App)
}).$mount(\'#app\')

当前(Vue3.0)
import { createApp } from \'vue\'import App from \'./App.vue\'
const app = createApp(App)
app.config.ignoredElements = [/^app-/]
app.use(/* ... */)
app.mixin(/* ... */)
app.component(/* ... */)
app.directive(/* ... */)
app.mount(\'#app\')

新全域性API
import { createApp } from \'vue\'import App from \'./App.vue\'
const app = createApp(App)

全域性对映API
1.全域性配置Vue.config -> app.config
2.注册型别API
Vue.component -> app.component
Vue.directive -> app.directive
Vue.filter -> app.filter
3.扩充套件型别API
Vue.mixin -> app.mixin
Vue.use -> app.use
手动挂载
const rootInstance = app.mount(\'#app\')rootInstance instanceof Vue // true
也可以接受第二引数props
app.mount(\'#app\', {
// props to be passed to root component
})
依赖注册
// in the entryapp.provide({
[ThemeSymbol]: theme
})
// in a child component
export default {
inject: {
theme: {
from: ThemeSymbol
}
},
template: ``
}

缺陷
Vue2.x中,许多库和外挂在UMD构建的时候是自动安装的,如路由vue-router:自动安装的时候会呼叫Vue.use(),在上述“扩充套件型别API”已表明,Vue.use()修正为例项app.use(),Vue.use已不再使用,当然会提供预警资讯。





























