[英]How to use vue-router with vue-touch-events
I tried to use vue-router
with vue-touch-events
this way:我尝试以这种方式将
vue-router
与vue-touch-events
一起使用:
<i v-touch="go('home')" class="fas fa-bars"></i>
<script>
export default {
name: "Nav",
methods: {
go: function(state) {
this.$router.push(state)
}
}
}
</script>
This does not work as go('home')
is executed every time the view renders and not on touch/tap.这不起作用,因为每次视图呈现时都会执行
go('home')
而不是在触摸/点击时执行。
The v-touch
value must be a function; v-touch
值必须是一个函数; go('home')
will be called immediately and returns undefined
which is not a function. go('home')
将被立即调用并返回undefined
这不是一个函数。
Try this instead:试试这个:
<i v-touch="() => go('home')" class="fas fa-bars"></i>
v-on
is the only directive that accepts the syntax you used; v-on
是唯一接受您使用的语法的指令; the Vue template compiler will not wrap your expression in a function for other directives which is why you must do it manually. Vue 模板编译器不会将您的表达式包装在其他指令的函数中,这就是您必须手动执行的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.