赞
踩
首先安装axios
// axios import global from './components/apicom/apicom' Vue.prototype.api = global.apicom // 绑定原型链的公共api import axios from 'axios'; Vue.prototype.$axios = axios; axios.defaults.withCredentials = true; //让ajax携带cookie 或者 //axios请求配置及拦截 import axios from 'axios' Vue.prototype.axios= axios; axios.defaults.baseURL = 'xxxxxxxx'; axios.interceptors.request.use(function (config) { // console.log(localStorage.getItem('admin_info')) let token = '' if(localStorage.getItem('admin_info') == null){ return config }else{ token = JSON.parse(localStorage.getItem('admin_info')).token } console.log(token) if(config.data == '' || config.data == null || config.data ==undefined){ if (token) { config.params['token'] = token } return config }else{ if (token) { config.data['token'] = token } return config } }, function (error) { return Promise.reject(error) })
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。