1.全局API的转移
- Vue2.x有许多全局API和配置
- 例如:注册全局组件,注册全局指令等。
//注册全局组件
Vue.component('myButton',{
data:()=>({
count:0
}),
template:'<button @click="count++'>Clicked{{count}}</button>'
})
//注册全局指令
Vue.directive('focus',{
inserted:el=>el.focus()
})
- Vue3中对这些API做出了调整:
- 将全局的API,即:Vue.xxx调整到应用实例(app)上
2.x的Vue.config.xxxx 3.x改为:app.config.xxx
2.x的Vue.config.productionTip//取消生产环境代码的提示,在3.x版本移除
2.x的Vue.component 3.x改为app.component
2.x的Vue.mixin 3.x改为app.mixin
2.x的Vue.use 3.x改为app.use
2.x的Vue.prototype 3.x改为app.config.globalProperties