一、安装axiosvue
(1)在npm环境下安装ios
有时候直接安装 axios 在 vuecil 会报错npm
先安装!axios
npm install axios
而后!this
npm install --save axios vue-axios
(2)在main.js里配置引入url
import axios from 'axios'
Vue.prototype.$http = axios
(3)在模块里的用法prototype
// API.getLogin 是接口路径urlrouter
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); });