axios 的坑

必须安装axios 和qs

1、main.js中的配置

import axios from 'axios'

import qs from 'qs';

axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';

Vue.prototype.$ajax = axios;

Vue.prototype.$qs = qs;
 
 
.vue组建中使用方法
let param=this.$qs.stringify({
"username":this.name,"password":this.password
})
this.$ajax({
method: 'post',
url:domain.testUrl+ 'cupboard/loginapi/login',
dataType:"json",
// withCredentials: false,
data:param
}).then(function (response) {
console.log(response.data);
}).catch(function (error) {
console.log(error);
})
原文地址:https://www.cnblogs.com/huge1122/p/10524000.html