0条评论
还没有人评论过~
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')
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')
import { createApp } from 'vue'
import App from './App.vue'
const app = createApp(App)
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 entry
app.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已不再使用,当然会提供预警信息。