首页 > 解决方案 > 想要从 Vuejs 中的 AXIOS GET api 调用重定向到 URL

问题描述

获得 AXIOS api 响应后,我需要重定向到新选项卡中的 url。

目前我正在使用window.open("url")api 调用中实现这一点,如下所示。

viewimage(image) {
          Nova.request().get(`/showimage/`+image,)
              .then(response => {
                this.urlimage = response.request.responseURL;
                window.open(this.urlimage,'_blank');
               
              });
    },

但是我想确认在生产环境中在 axios 中使用 window.open("url") 的正确过程是否正确,因为我面临所有浏览器都被阻止的弹出窗口。

如果有任何其他替代方式来实现这一目标?请从你身边引导我。

谢谢,

标签: javascriptlaravelvue.jsvuejs2axios

解决方案


如果你使用 vue-router,你应该使用 router.push("yourroutename")。

否则,window.location.href = 'some url'; 适用于非单页应用程序。

原始答案:Vue.js 重定向到另一个页面


推荐阅读