1、 vue全局挂载的
Object.keys(directives).forEach((key) => {
Vue.directive(key, (directives as { [key: string ]: DirectiveOptions })[key])
})
Object.keys(filters).forEach((key) => {
Vue.filter(key, (filters as { [key: string ]: Function })[key])
})
Vue.prototype.$dayjs = dayjs
window.eventHub = new Vue()
Vue.prototype.$commonApi = commonApi
Vue.use(ElementUI)
2、vue配置:Vue.config.xxx
Vue.config.devtools = process.env.NODE_ENV !== 'production'
Vue.config.errorHandler = vueErrorHandler(自定义的方法)
3、整体原则
- (1)vue全局注册过滤器,使用Vue.filter
- (2)vue全局注册指令,使用Vue.directive
- (3)在vue原型上添加方法 Vue.prototype
- (4)在window对象上添加属性或方法 window.xxx = xxx
- (5)修改vue的全局配置 Vue.config.xxx
- (6)vue使用插件 Vue.use