Commit a945302ef2ab2eb17e7aadf5b235ccb94caa54ea
1 parent
11aa682f
axios
Showing
3 changed files
with
19 additions
and
10 deletions
src/api/httpRequest.js
| ... | ... | @@ -6,12 +6,7 @@ const CancelToken = axios.CancelToken; |
| 6 | 6 | //请求拦截器 // 在发送请求之前做些什么 |
| 7 | 7 | axios.interceptors.request.use(config => { |
| 8 | 8 | //发起请求时,取消掉当前正在进行的相同请求 |
| 9 | - if (promiseArr[config.url]) { | |
| 10 | - promiseArr[config.url]('操作取消') | |
| 11 | - promiseArr[config.url] = cancel | |
| 12 | - } else { | |
| 13 | - promiseArr[config.url] = cancel | |
| 14 | - } | |
| 9 | + config.headers['x-auth-token'] = '5a706458-5a67-4297-a009-30fb82a2fa45' | |
| 15 | 10 | return config |
| 16 | 11 | }, error => { |
| 17 | 12 | return Promise.reject(error) |
| ... | ... | @@ -73,11 +68,11 @@ axios.interceptors.response.use(response => { |
| 73 | 68 | }) |
| 74 | 69 | //基础url前缀 |
| 75 | 70 | //axios.defaults.baseURL = '/api' |
| 76 | -axios.defaults.baseURL = 'http://10.0.2.31:8096/'; | |
| 71 | +// axios.defaults.baseURL = 'http://10.0.2.31:8096/'; | |
| 77 | 72 | //设置默认请求头 |
| 78 | -axios.defaults.headers = { | |
| 79 | - 'X-Requested-With': 'XMLHttpRequest' | |
| 80 | -} | |
| 73 | +// axios.defaults.withCredentials=true;//让ajax携带cookie | |
| 74 | + | |
| 75 | +// axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8'; | |
| 81 | 76 | axios.defaults.timeout = 10000 |
| 82 | 77 | |
| 83 | 78 | export default { | ... | ... |
src/components/memberNum/index.vue
| ... | ... | @@ -38,6 +38,13 @@ |
| 38 | 38 | mounted() { |
| 39 | 39 | //会员总数 |
| 40 | 40 | this.memberNumTotal=this.formatNumToStr(); |
| 41 | + this.axios.post('http://39.98.54.240:8093/urban/intelligence/appuser/queryUserPersonStatistic', { | |
| 42 | + sysCode: '1001' | |
| 43 | + }).then((response)=>{ | |
| 44 | + console.log(response) | |
| 45 | + }).catch((response)=>{ | |
| 46 | + console.log(response); | |
| 47 | + }) | |
| 41 | 48 | }, |
| 42 | 49 | methods: { |
| 43 | 50 | /* | ... | ... |
src/main.js
| 1 | 1 | import Vue from 'vue' |
| 2 | 2 | import App from './App' |
| 3 | 3 | import router from './router/router' |
| 4 | + | |
| 5 | +import axios from 'axios' | |
| 6 | +import Qs from 'qs' | |
| 7 | +//QS是axios库中带的,不需要我们再npm安装一个 | |
| 8 | + | |
| 9 | +Vue.prototype.axios = axios; | |
| 10 | +Vue.prototype.qs = Qs | |
| 4 | 11 | //import { powerRouter } from './router'; |
| 5 | 12 | import store from './store'; |
| 6 | 13 | import ElementUI from 'element-ui' | ... | ... |