router.beforeResolve根據不同頁面定義不同$http

Vue.prototype.$http = axios;
Vue.config.productionTip = false;

Vue.prototype.$event = new Vue();

/* eslint-disable no-new */
var init = function() {
  new Vue({
    el: "#app",
    router,
    store,
    template: "<App/>",
    render: h => h(App)
  });
};
//這裏根據單頁面name的指向不同,去訪問的接口域名也不同
router.beforeResolve((to, from, next) => {
  let url;
  if (
    to.matched[0].name == "broker-shop" ||
    to.matched[0].name == "information"
  ) {
    url = "https://ddd.zhaoshang800.com";
  } else if (to.matched[0].name == "brokerage-list") {
    url = "https://aaa.zhaoshang800.com";
  } else if (to.matched[0].name == "sellhot") {
    url = "https://bbb.zhaoshang800.com";
  } else if (to.matched[0].name == "enterprise-index") {
    url = "http://ccc.zhaoshang800.com";
  } else {
    url = "https://" + location.host;
  }
  Vue.prototype.$http.defaults.baseURL = url;
  next();
});

 

發佈了153 篇原創文章 · 獲贊 52 · 訪問量 24萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章