npm install axios
//引入axios
import axios from ‘axios‘
//axios默认配置
axios.defaults.baseURL="http://localhost:8080"
axios.defaults.timeout=5000
axios.defaults.headers.post[‘Content-Type‘] = ‘application/x-www-form-urlencoded;charset=UTF-8‘;
//修改原型链,全局使用axios,这样之后可在每个组件的methods中调用$axios命令完成数据请求
Vue.prototype.$axios=axios
npm install qs
Vue.prototype.$qs=qs
this.$axios
.post(
"/user/login",
this.$qs.stringify({
xh: this.xh,
password: this.$md5(this.password1)
})
)
.then(response => {
})
.catch(error => {
});
this.$axios
.get("/user/select", {
params: {
xh: this.ruleForm.xh
}
})
.then(response => {
} else {
}
})
.catch(error => {});
原文:https://www.cnblogs.com/xymaxbf/p/12455415.html