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 · 访问量 23万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 技术黑板 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览