当前位置: 首页 > Web前端 > HTML5

vue.use学习

时间:2023-04-04 23:51:45 HTML5

vue.use学习我们都知道每次使用Vue.use都会想到Vue.use(ElementUI)、Vue.use(MintUI)等,但是发现,axios不需要使用Vue.use(),这是为什么呢?严格来说,Vue.use()方法依赖于Vue组件,而axios只是一个处理请求的库,并不依赖于Vue。所以,他不需要Vue.use,因为他不用。install方法,其他使用Vue.use()的方法使用install方法。说了这么多,不知道对不对。这是我个人的理解。如有错误,希望网友们提出宝贵意见,帮助我提高自己。谢谢,不喜勿喷。接下来我们看看组件是如何使用Vue.use()的。首先,让我们看一下目录结构。自己安装node和vue-cli3。我们在components目录下创建一个loading文件夹,并新建一个index.js文件。接下来在loading.vue文件里随便写点东西,loading.vueindex.js//importcomponentimportLoadingComponentfrom'./loading.vue'//定义Loading对象constLoading={//install是默认方法。外界在使用这个组件的时候,会调用自己的install方法,同时传递一个Vue类的参数。install:function(Vue){Vue.component('Loading',LoadingComponent)}}//exportexportdefaultLoading最后我们将项目引入main.js运行后,可以看到loading字样。有兴趣的可以关注我微信公众号更多精彩内容在公众号