vue使用axios
1.在mina.js中写下面代码
import Axios from "axios";
Vue.prototype.HOST = "http://localhost:4000";
Vue.prototype.$axios = Axios;
2.在页面使用的时候是
this.$axios
.post(this.HOST + "/api/login", {
username: this.username,
password: this.password
})
.then(*result* => {
console.log(result.data);
this.msg = result.data.msg;
})
.catch(*err* => {
console.log(err);
});