Vue.http.jsonp(url,{ params:data||{} }).then(response=>{ let ret = response.data; if (ret.status==0) { resolve(ret.data); }else{ Vue.message.error(ret.msg); } },error=>{ })
[t.APP_SET_ACCESS_TOKEN] (state, data) { state.access_token = data.access_token state.expires = + new Date() + (parseInt(data.expires_in) * 1000) // Add global 'Authorization' header Vue.http.headers.common['Authorization'] = data.token_type +' '+ data.access_token // Add global 'customerId' header Vue.http.headers.common['customerId'] = USER_ID }
leaveChat({ commit }, username) { return new Promise(async (resolve, reject) => { try { const { body : { code } } = await Vue.http.post(`${url}/auth/logout`, { username }) if (code !== 200) reject() commit(STORE_ACTIONS.leaveChat) resolve() } catch (error) { reject(error) } }) }
getConnectedClients() { return Vue.http.get(`${endpoint}/clients`) }
Vue.http.interceptors.push((request, next) => { store.commit(types.START_FETCHING); next((response) => { store.commit(types.STOP_FETCHING); }); });
Vue.http.get(`articles?limit=${pageSize}&offset=0`) .then(response => { const _articles = response.body.posts; commit('getPosts', _articles); commit('setPostCount', response.body.postCount) });
joinRoom({ commit }, data) { return new Promise(async (resolve, reject) => { try { const { body } = await Vue.http.post(`${url}/auth/login`, data) if (body.code === 400 || body.code === 401 || body.code === 500) { reject({ message: body.message }) } commit(STORE_ACTIONS.joinRoom, data) resolve() } catch (error) { reject(error) } }) }
_axios(url, data = {}, method) { const isGet = method === 'get'; const isFormDataType = data instanceof FormData; return Vue.http({ baseURL: API_URL_RPEFIX, method: method, url: url, data: isGet ? null : data, params: Object.assign({}, {t: +new Date}, isGet ? data : {}), headers: { 'Accept': 'application/json', 'Content-Type': isFormDataType ? 'multipart/form-data' : 'application/json', 'Authorization': store.state.userInfo.token } }).then((response) => { return response.data; }); }
auth ({commit}) { return Vue.http({ method: 'post', url: ENDPOINT_IDENTITYSERVER, body: 'grant_type=client_credentials', headers: { 'Authorization': 'Basic ' + btoa(encodeURIComponent(CLIENT_ID) + ':' + encodeURIComponent(CLIENT_SECRET)), 'Accept': 'application/json', 'Content-Type': 'application/x-www-form-urlencoded;' } }).then(r => { return r.status == 200 ? ( commit(t.APP_SET_ACCESS_TOKEN, r.body), Promise.resolve() ) : ( Promise.reject() ) }) }
Vue.http.get('posts/categories') .then(response => { commit('setCategories', response.body.cats) })
Vue.http.post('posts').then(response => { commit('createPost', response.body) });
Vue.http.get(`articles?limit=${pageSize}&offset=${offset}`) .then(response => { const _articles = response.body.posts; commit('setPageAvailable', {value, moveType}); commit('setActivePage', value); commit('getPosts', _articles); });
Vue.http.interceptors.push((request, next) => { store.commit(types.START_FETCHING); next((response) => { store.commit(types.STOP_FETCHING); }); });
_axios(url, data = {}, method) { const isGet = method === 'get'; const isFormDataType = data instanceof FormData; return Vue.http({ baseURL: API_URL_RPEFIX, method: method, url: url, data: isGet ? null : data, params: Object.assign({}, {t: +new Date}, isGet ? data : {}), headers: { 'Accept': 'application/json', 'Content-Type': isFormDataType ? 'multipart/form-data' : 'application/json', 'Authorization': store.state.userInfo.token } }).then((response) => { return response.data; }); }