vue axios跨域的get和post的使用
1.首先在main.js中引用axios。import axios from 'axios';Vue.prototype.$http = axios;axios.defaults.baseURL = 'http://localhost';2.get和post的用法getData () { console.log('-------getData') let that = th
1.首先在main.js中引用axios。
import axios from 'axios';
Vue.prototype.$http = axios;
axios.defaults.baseURL = 'http://localhost';
2.get和post的用法
getData () {
console.log('-------getData')
let that = this;
that.$http.get('http://localhost:8080/MySpring').then(function (response) {
that.serverData = response.data
console.log(response.data)
}).catch(function (error) {
console.log(error)
})
},
post () {
let param = new URLSearchParams();
param.append("name", "admin");
param.append("sex", "男");
param.append("age", 11);
this.$http.post('http://localhost:8080/MySpring', param, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
}).then(function (response) {
console.log(response)
}).catch(function (err) {
console.log(err)
})
}
更多推荐
所有评论(0)