Analysis on the use of Vue.use () about AXIOS

Recently learned AXIOS, in the use process, there is some problem, I feel that it is necessary to share it, about the basic knowledge of AXIOS, you can refer to this article: AXIOS basic entry tutorial, don’t say more below, come and see the detailed introduction.

I believe that many people will use

Vue.use () when using VUE to use others. For example: Vue.use (Vuerouter) , Vue.use (MINTUI) . However, when using AXIOS, you don't need to use Vue.use (Axios) . That's why?

Answer

Because AXIOS is not install.

What do you mean? Next, we customize a component of

Vue.use ()
, that is, there is install component. After reading it, you will understand.

Define component

Generates Vue Init WebPack-Simple Custom-Global-Component

Custom-Global-Component is a new file Clip name



CD Custom-Global-Component enters the folder


NPM INSTALL installed this time required Module


NPM Run DEV running item


If it can be opened normally, the next step


This is the current project directory:


project directory

关于axios不能使用Vue.use()浅析 1. create folders and files in the figure below

project directory

关于axios不能使用Vue.use()浅析 2. definitions in Loading.vue an assembly

Loading …
   
3. jndex.js incorporated in Loading.vue, and export

// introduction means import LoadingComponent from ‘./loading.vue’// Loading objects defined const Loading = {// install the default method. When the outside at the time of use this component, will call the install process itself, as well as pass a parameter Vue this class. install: function (Vue) {Vue.component ( ‘Loading’, LoadingComponent)}} // derived export default Loading

   4 in the main.js. introduced under loading index file 

// where ‘./components/loading/index’ of / index can not write, webpack will automatically find and load index . If other name would need to write on. import Loading from ‘./components/loading/indeX ‘// This time you need use (loading) if you do not write Vue.use (), the browser will report an error, you can try Vue.use (loading)

   5. Write a good component tag 

   

6. It should be understood here, use AXIOS. It doesn't need to use

Vue.use (Axios) , it can be used directly because the developer does not write install when encapsulating AXIOS. As for why you didn't write, then you didn't know.
The above is the full content of this article, I hope this paper has a certain reference value for everyone’s learning or work. If you have any questions You can leave a message to communicate, thank you for your support of Tumi Cloud.
© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment