In vue:
①The first way of writing
this.$axios.get('http://wthrcdn.etouch.cn/weather_mini', {
params: {
city: "北京"
}
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
})
②The second way of writing
ps:
The params in the following paragraph must be written as params, not data, because when axios sends a request, params is added to the url string for get requests, and data is added to the request body Yes, for post requests.
this.$axios({
method:'get',
dataType:'json',
contentType:"application/json",
url:'http://wthrcdn.etouch.cn/weather_mini',
params:{
city:"北京"
},
}).then((res)=>{
console.log(res);
})
Need to configure the environment before using axios
①Execute commands in cmd
npm install axios
②You can see this line in package.json
③Write these lines in src/main.js
import axios from 'axios'
Vue.config.productionTip = false
Vue.prototype.$axios=axios
Vue.config.productionTip = false
④npm run serve can use axios