// axios
// 在main.js中 导入 axios,在组件中使用时不需要再进行导入
import axios from 'axios'
// 全局配置 axios 的请求根路径
axios.defaults.baseURL = 'http://****'
// 把axios挂载到Vue的原型上
Vue.prototype.$http = axios
// 在每个vue组件中要发起请求,直接调用this.$http.xxx
// 缺点:无法实现 api 的复用s
安装axios
this.$http
.post(
"/user/login", //请求的后台接口
{
account: this.input,
password: this.password,
} //传给后台的参数
)
.then(({ data }) => {
console.log(data);
});