Commit d5a54bbc by 姜雷

请求中添加notLoading参数在不需要显示loading状态时设为true

parent 104ea2f5
...@@ -12,7 +12,8 @@ const createBaseFetch = config => { ...@@ -12,7 +12,8 @@ const createBaseFetch = config => {
// request拦截器 // request拦截器
service.interceptors.request.use( service.interceptors.request.use(
conf => { conf => {
store.dispatch('fetchStart'); const { notLoading } = conf;
store.dispatch('fetchStart', notLoading);
conf.headers = { conf.headers = {
...conf.headers, ...conf.headers,
reqSource: 'pc', reqSource: 'pc',
...@@ -34,7 +35,8 @@ const createBaseFetch = config => { ...@@ -34,7 +35,8 @@ const createBaseFetch = config => {
* code为非 1000 是抛错 * code为非 1000 是抛错
*/ */
setTimeout(() => { setTimeout(() => {
store.dispatch('fetchDone'); const { notLoading } = response.config;
store.dispatch('fetchDone', notLoading);
}, 500); }, 500);
if (res.code !== 1000) { if (res.code !== 1000) {
if ( if (
......
...@@ -12,20 +12,24 @@ const getters = { ...@@ -12,20 +12,24 @@ const getters = {
}; };
const actions = { const actions = {
fetchStart({ commit }) { fetchStart({ commit }, notLoading) {
commit(FETCH_START); commit(FETCH_START, notLoading);
}, },
fetchDone({ commit }) { fetchDone({ commit }, notLoading) {
commit(FETCH_DONE); commit(FETCH_DONE, notLoading);
}, },
}; };
const mutations = { const mutations = {
[FETCH_START](state) { [FETCH_START](state, notLoading) {
fetchCount++; if (!notLoading) {
state.loading = true; fetchCount++;
state.loading = true;
}
}, },
[FETCH_DONE](state) { [FETCH_DONE](state, notLoading) {
fetchCount--; if (!notLoading) {
fetchCount--;
}
if (fetchCount === 0) { if (fetchCount === 0) {
state.loading = false; state.loading = false;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment