1、安装axios
(1)在npm环境下安装
有时候直接安装 axios 在 vuecil 会报错
先安装!
npm install axios
然后!
npm install --save axios vue-axios
(2)在main.js里配置引入
import axios from 'axios'
Vue.prototype.$http = axios
(3)在模块里的用法
// API.getLogin 是接口路径url
this.$http.get(API.getLogin, { params: { username: this.username, password: this.password // captcha: this.captcha } }) .then((res) => { let data = res.data; console.log(data); if(data.result == "success"){ localStorage.setItem("username", this.username); // vm.$router.push({path: '/home'}); }else{ this.error = true; vm.errorMsg = data.result; vm.refresh(); } }).catch((error) => { // console.log(error); });