一、安裝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); });