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,12 +6,7 @@ const CancelToken = axios.CancelToken; | ||
| 6 | //请求拦截器 // 在发送请求之前做些什么 | 6 | //请求拦截器 // 在发送请求之前做些什么 |
| 7 | axios.interceptors.request.use(config => { | 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 | return config | 10 | return config |
| 16 | }, error => { | 11 | }, error => { |
| 17 | return Promise.reject(error) | 12 | return Promise.reject(error) |
| @@ -73,11 +68,11 @@ axios.interceptors.response.use(response => { | @@ -73,11 +68,11 @@ axios.interceptors.response.use(response => { | ||
| 73 | }) | 68 | }) |
| 74 | //基础url前缀 | 69 | //基础url前缀 |
| 75 | //axios.defaults.baseURL = '/api' | 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 | axios.defaults.timeout = 10000 | 76 | axios.defaults.timeout = 10000 |
| 82 | 77 | ||
| 83 | export default { | 78 | export default { |
src/components/memberNum/index.vue
| @@ -38,6 +38,13 @@ | @@ -38,6 +38,13 @@ | ||
| 38 | mounted() { | 38 | mounted() { |
| 39 | //会员总数 | 39 | //会员总数 |
| 40 | this.memberNumTotal=this.formatNumToStr(); | 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 | methods: { | 49 | methods: { |
| 43 | /* | 50 | /* |
src/main.js
| 1 | import Vue from 'vue' | 1 | import Vue from 'vue' |
| 2 | import App from './App' | 2 | import App from './App' |
| 3 | import router from './router/router' | 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 | //import { powerRouter } from './router'; | 11 | //import { powerRouter } from './router'; |
| 5 | import store from './store'; | 12 | import store from './store'; |
| 6 | import ElementUI from 'element-ui' | 13 | import ElementUI from 'element-ui' |