Vue.use(ElementUI)
Vue.prototype.$axios = axios
Vue.config.productionTip = false
new Vue({
el: '#app',
router,
store,
//axios,
i18n,
template: '<App/>',
components: { App }
})
在组件中使用$axios正常,this.$axios.get(可以正常执行
但如果用下面这种方式就会提示TypeError: Cannot read property 'get' of undefined
Vue.use(ElementUI)
//Vue.prototype.$axios = axios
Vue.config.productionTip = false
new Vue({
el: '#app',
router,
store,
axios,
i18n,
template: '<App/>',
components: { App }
})
那么这两种到底有什么区别呢?从我自己了解到的内容,只知道在prototpye中使用的是实例中的属性,在vue(){}中的是全局属性,按照这种逻辑来说 我注册到new vue(){}中不应该有问题啊,可是为什么不行呢,
还有我理解Vue.use(ElementUI) 使用use方式的就是在使用标签库,我的理解对吗?
区别是: