停止路由器链接直到确认返回
我正在建立一个食品配送网站。我需要告诉用户,当他点击通过 vuejs2 router-link 将他重定向到另一个页面的组件时,他的购物车将被删除。 目前我有这个:
<RestaurantBox
v-for="(restaurant, index) in activeRestaurants"
:key="`restaurant${index}`"
:restaurant="restaurant"
@click.native="confirmChange"
/>
使用给定的功能:
confirmChange() {
if (!confirm('Attenzione! Se cambi ristorante perderai quello che hai messo nel carrello.')) {
location.href = '/restaurants/' + this.activeType.slug;
}
}
这有点有效:如果我单击取消,if中的语句会执行它应该执行的操作,但是当我单击组件时,它会在确认之前通过router-link更改url (),所以基本上没什么用。 有什么想法吗?
I'm building a food-delivery website. I need to tell the user that, when he clicks on the component which redirects him in another page via vuejs2 router-link, his shopping cart will be deleted.
At the moment I have this:
<RestaurantBox
v-for="(restaurant, index) in activeRestaurants"
:key="`restaurant${index}`"
:restaurant="restaurant"
@click.native="confirmChange"
/>
with the given function:
confirmChange() {
if (!confirm('Attenzione! Se cambi ristorante perderai quello che hai messo nel carrello.')) {
location.href = '/restaurants/' + this.activeType.slug;
}
}
This kinda works: if I click cancel, the statement in the if does what it should do, but when I click on the component it changes the url via router-link before the confirm(), so it's basically useless.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论