我想在Vue.js中做一个类似于香草javascript的重定向
window.location.href = 'some_url'
我如何在Vue.js中实现这一点?
我想在Vue.js中做一个类似于香草javascript的重定向
window.location.href = 'some_url'
我如何在Vue.js中实现这一点?
当前回答
只使用:
window.location.href = "http://siwei.me"
不要使用vue-router,否则会被重定向到 “http://yoursite.com/ # ! / http://siwei.me”
我的环境:节点6.2.1,vue 1.0.21, Ubuntu。
其他回答
window.location = url;
'url'是你想重定向的web url。
所以,我所寻找的只是在哪里放window.location.href和结论,我来的是,最好和最快的方式重定向是在路由(这样,我们不等待任何东西加载之前,我们重定向)。
是这样的:
routes: [
{
path: "/",
name: "ExampleRoot",
component: exampleComponent,
meta: {
title: "_exampleTitle"
},
beforeEnter: () => {
window.location.href = 'https://www.myurl.io';
}
}]
也许它会帮助别人。
为了与您最初的要求保持一致:
window.location.href = 'some_url'
你可以这样做:
<div @click="this.window.location='some_url'">
</div>
注意,这并没有利用Vue的路由器,但如果你想“在Vue.js中做一个类似于香草javascript的重定向”,这是可行的。
也可以试试这个…
router.push({ name: 'myRoute' })
美元。路由器。Push可以用来重定向vue.js中的页面
this.$router.push(url);
这个例子。美元router.push(“回家”); 此方法不会刷新页面