【问题标题】:Going to a URL using VueJS使用 VueJS 访问 URL
【发布时间】:2017-03-24 20:35:26
【问题描述】:

我正在尝试访问这样的 URL:

methods: {
    show (file) {
        this.$router.go('/file/' + file.path + '?token=' + localStorage.getItem('jwt-token'));
    }
}

我没有尝试访问组件。我只想去以下网址:

'/file/' + file.path + '?token=' + localStorage.getItem('jwt-token')

但它不起作用。它正在将我重定向到主页。

我怎样才能完成这项工作?

【问题讨论】:

  • vue 路由器 1 或 2?
  • 你发现了吗?以下任何答案对您有帮助吗?

标签: javascript vue.js vue-router


【解决方案1】:

这应该在 vue router 2.0 中工作:

this.$router.push({path: '/file/' + file.path , query: {token: localStorage.getItem('jwt-token')} })

【讨论】:

    【解决方案2】:

    如果你想去一个不是 Vue 路由器 URL 的 URL,你可以使用标准的 javascript 通过:

    window.location.href = '/file/' + file.path + '?token=' + localStorage.getItem('jwt-token');
    

    this answer

    【讨论】:

    • 我用vue2。这个答案对我不起作用。这仍然让我进入主页。例如,window.location.href = "www.gotosite.com" 将我转发到example.com/www.gotosite.org
    • @noypee 这是因为您应该将https:// 放在您的网址前面,否则它只会转到相对网址
    猜你喜欢
    • 2022-01-22
    • 2021-08-19
    • 2020-09-26
    • 2021-06-16
    • 2017-06-15
    • 2017-06-22
    • 2018-05-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多