简体   繁体   中英

How to use vue-router with vue-touch-events

I tried to use vue-router with vue-touch-events this way:

<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.

The v-touch value must be a function; go('home') will be called immediately and returns undefined which is not a function.

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; the Vue template compiler will not wrap your expression in a function for other directives which is why you must do it manually.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM