2016-11-10 54 views
0

我試圖去這樣的URL網址:要使用VueJS

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

我不想去一個組成部分。我只想去以下網址:

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

但它不起作用。它將我重定向到主頁。

我該如何做到這一點?

+2

VUE路由器1或2? – nils

+0

你發現了嗎?下面的答案對你有幫助嗎? – jeerbl

回答

4

如果你想去哪個不是Vue公司路由器的URL網址,你可以通過使用標準的JavaScript做到這一點:

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

this answer

+0

我使用vue2。這個答案對我不起作用。這仍然讓我到主頁。例如,window.location.href =「www.gotosite.com」轉發給我http://example.com/www.gotosite.org – codely

+0

@noypee這是因爲你應該把「https://」放在前面您的網址,否則它只是轉到相對URL – jeerbl

1

這應該在VUE路由器2.0工作:

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