【6月日新计划更文活动】第28天
全局API的转移
-
Vue2 有许多全局 API 和配置
-
例如:注册全局组件、注册全局指令等
// 注册全局组件 Vue.component('MyButton', { data: () => ({ count: 0 }), template: `<button @click="count++">Clicked {{ count }} times. </button>` }) // 注册全局指令 Vue.directive('focus', { inserted: el => el.focus() })
-
-
Vue3中对这些API做出了调整
- 将全局的 API,即:
Vue.xxx调整到应用实例 (app) 上
-- 2.x全局 API (Vue) -- -- 3.x实例 API (app) -- Vue.config.xxx app.config.xxx Vue.config.productionTip 移除 (生产版本提示) Vue.component app.component Vue.directive app.directive Vue.mixin app.mixin Vue.use app.use Vue.prototype app.config.globalProperties (全局属性) - 将全局的 API,即: