最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Vue開發(fā)中整合axios的文件整理

 更新時(shí)間:2017年04月29日 11:52:38   作者:彬仔  
這篇文章主要給大家整理了在Vue開發(fā)中整合axios要用到的文件,在vue開發(fā)中,不可避免要整合axios,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友們下面來(lái)一起看看吧。

前言

大家在vue日常開發(fā)中,不可避免要整合axios,這里簡(jiǎn)單記錄一下整合中的文件,方便以后使用查找。下面來(lái)看看詳細(xì)的介紹。

整合方法

整合文件axios.js

import axios from 'axios';
// 適配vue-resource
const instance = axios.create();
instance.interceptors.request.use(config=> {
//Serialize.decode(config);
return config;
});
instance.interceptors.response.use(response=> {
return response.data;
}, err=> {
if (err.response) {
axios.post('/v1/error', err.response);
return Promise.reject(err.response.data);
}
return Promise.reject({ code: 1024, message: err.message });
});
function plugin(Vue) {
if (plugin.installed) {
return;
}
Vue.http = instance;
}
if (typeof window !== 'undefined' && window.Vue) {
window.Vue.use(plugin);
}
export default plugin;

vue插件使用 app.js

import Vue from 'vue';
import App from './App.vue';
import store from './store';
import { sync } from 'vuex-router-sync';
import router from './router';
import * as filters from './filters';
import yxui from 'yxui/dist/yxui.min';
import axios from './axios';
Vue.use(yxui);
Vue.use(axios);
// sync the router with the vuex store.
// this registers `store.state.route`
sync(store, router);
// register global utility filters.
Object.keys(filters).forEach(key => {
Vue.filter(key, filters[key]);
});
// create the app instance.
// here we inject the router and store to all child components,
// making them available everywhere as `this.$router` and `this.$store`.
const app = new Vue({
router,
store,
...App
});
// expose the app, the router and the store.
// note we not mounting the app here, since bootstrapping will be
// different depending on whether we are in browser or on the server.
export { app, router, store };

在vuex action 中使用:

actions: {
// adList
[TypesAds.AD_GET_LIST](ctx, params){
return Vue.http.get('/v1/api/ads/list', {params}).then(data=> {
ctx.commit(TypesAds.AD_GET_LIST, data);
return data;
}).catch(err=> {
//統(tǒng)一錯(cuò)誤處理
Vue.$message.error(err.msg);
});
}
}

總結(jié)

以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,如果有疑問(wèn)大家可以留言交流,謝謝大家對(duì)腳本之家的支持。

相關(guān)文章

  • 使用vNode實(shí)現(xiàn)給列表字段打標(biāo)簽

    使用vNode實(shí)現(xiàn)給列表字段打標(biāo)簽

    這篇文章主要為大家介紹了使用vNode實(shí)現(xiàn)給列表字段打標(biāo)簽示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-09-09
  • Vue中的v-for循環(huán)key屬性注意事項(xiàng)小結(jié)

    Vue中的v-for循環(huán)key屬性注意事項(xiàng)小結(jié)

    這篇文章主要介紹了Vue中的v-for循環(huán)key屬性注意事項(xiàng)小結(jié),非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2018-08-08
  • vue項(xiàng)目main.js配置及使用方法

    vue項(xiàng)目main.js配置及使用方法

    main.js是項(xiàng)目的入口文件,項(xiàng)目中所有的頁(yè)面都會(huì)加載main.js,本文主要介紹了vue項(xiàng)目main.js配置及使用方法,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
    2023-05-05
  • Vue 3 中的 toRef 和 toRefs 函數(shù)案例講解

    Vue 3 中的 toRef 和 toRefs 函數(shù)案例講解

    這篇文章主要介紹了Vue 3 中的 toRef 和 toRefs 函數(shù),toRef 和 toRefs 函數(shù)是 Vue 3 中的兩個(gè)非常有用的函數(shù),它們可以幫助我們更好地管理組件中的響應(yīng)式數(shù)據(jù),并且可以提高組件的性能和用戶體驗(yàn),需要的朋友可以參考下
    2024-06-06
  • Vue實(shí)現(xiàn)簡(jiǎn)單跑馬燈特效

    Vue實(shí)現(xiàn)簡(jiǎn)單跑馬燈特效

    這篇文章主要為大家詳細(xì)介紹了Vue實(shí)現(xiàn)簡(jiǎn)單跑馬燈特效,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-05-05
  • Vue插值、表達(dá)式、分隔符、指令知識(shí)小結(jié)

    Vue插值、表達(dá)式、分隔符、指令知識(shí)小結(jié)

    這篇文章主要介紹了Vue插值、表達(dá)式、分隔符、指令的相關(guān)知識(shí),文中給大家提到了去除vue插值表達(dá)式{{}}的方法,需要的朋友可以參考下
    2018-10-10
  • vue卡片式點(diǎn)擊切換圖片組件使用詳解

    vue卡片式點(diǎn)擊切換圖片組件使用詳解

    這篇文章主要為大家詳細(xì)介紹了vue卡片式點(diǎn)擊切換圖片組件的使用方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-06-06
  • 在Vue3項(xiàng)目中使用VueCropper裁剪組件實(shí)現(xiàn)裁剪及預(yù)覽效果

    在Vue3項(xiàng)目中使用VueCropper裁剪組件實(shí)現(xiàn)裁剪及預(yù)覽效果

    這篇文章主要介紹了在Vue3項(xiàng)目中使用VueCropper裁剪組件(裁剪及預(yù)覽效果),本文分步驟結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-07-07
  • vue 項(xiàng)目代碼拆分的方案

    vue 項(xiàng)目代碼拆分的方案

    這篇文章主要介紹了vue 項(xiàng)目代碼拆分的方案,幫助大家更好的理解和學(xué)習(xí)使用vue框架,感興趣的朋友可以了解下
    2021-03-03
  • Vue中強(qiáng)制組件重新渲染的正確方法

    Vue中強(qiáng)制組件重新渲染的正確方法

    這篇文章主要介紹了Vue中強(qiáng)制組件重新渲染的正確方法,幫助大家更好的理解和使用vue框架,感興趣的朋友可以了解下
    2021-01-01

最新評(píng)論

闽侯县| 崇信县| 古蔺县| 阜新市| 南澳县| 桂东县| 赤城县| 门源| 新营市| 阳新县| 广宗县| 平泉县| 越西县| 西宁市| 昂仁县| 长垣县| 瑞金市| 新闻| 石棉县| 松溪县| 乌鲁木齐市| 新闻| 桂东县| 息烽县| 新巴尔虎右旗| 永安市| 宜春市| 长子县| 盘山县| 宁都县| 额尔古纳市| 陆川县| 公安县| 南靖县| 洪雅县| 蒙自县| 视频| 高碑店市| 隆德县| 多伦县| 乌苏市|