In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
The purpose of this article is to share with you about the use of axios in vuejs. I think it is very practical, so I share it with you. I hope you can get something after reading this article.
How to use axios in vuejs: 1. Install axios;2, reference axios;3 in the main.js page, and use it through "created () {this.$axios ({method:'post',url:'api'...}").
This article operating environment: Windows7 system, vue2.9.6 version, DELL G3 computer.
What is the use of axios in vuejs?
Basic usage of axios in vue
1. Install axios first:
1): npm install2): npm install vue-axios-- save3): npm install qs.js-- save / / this step can be ignored, its function is to convert the json format directly into the format required by data 2. After the installation is successful, refer to: import Vue from 'vue'import axios from' axios'Vue.prototype.$axios = axios / / global registration on the main.js page, using the method: this.$axiosVue.prototype.qs = qs / / global registration How to use it: this.qs3 finally starts using the request: export default {data () {return {userId:666, token:'',}}, created () {this.$axios ({method:'post', url:'api') Data:this.qs.stringify ({/ / here is the data sent to the backend userId:this.userId, token:this.token })}) .then ((response) = > {/ / the syntax of ES6 console.log (response) / / data returned after a successful request}) .catch ((error) = > console.log (error) / / data returned after a failed request})}
Initiate multiple requests at the same time
Function getUserAccount () {return axios.get ('/ user/12345');} function getUserPermissions () {return axios.get ('/ user/12345/permissions');} axios.all ([getUserAccount (), getUserPermissions ()]) .then (axios.spread (function (acct, perms) {/ / Both requests are now complete})) To create an instance you can create an axios instance axios.creat ([config]) var instance = axios.create with a common configuration ({baseURL: 'https://some-domain.com/api/', timeout: 1000, headers: {' Xmurley headers: 'foobar'}})
This is how axios is used in vuejs. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.