说明: axios封装 vue路由 tp路由 去掉index.php头,建议先下载源码再看。
安装axios:
使用 npm:
$ npm install axios |
使用 bower:
$ bower install axios |
引用:
import Vue from 'vue';
import App from './App.vue';
//导入
import http from 'axios'
import '../api/config'
http.defaults.baseURL = 'https://XXXXXXX';//服务器地址
//请求头声明
http.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
http.defaults.headers.get['Content-Type'] = 'application/x-www-form-urlencoded';
Vue.prototype.$http=http;