Home

Issue: 2637

this.$router not working in methods

[issue link]

I try to navigate into my nuxt-child with a slider. In order to that, i want to use this.$router.push() in a methods but it’s not working

Cannot read property 'push' of undefined
This my error

export default {
  data () {
    const vue = this
    return {
      intro: {
        title: 'Toutes les Actualités',
        content: 'Retrouvez toutes les actualités concernant le monde du surf et la Fédération Française de Surf. Ne loupez aucune nouveauté !'
      },
      links: ['sportives', 'federales', 'regionales'],
      swiperOptionLinks: {
        mousewheel: {
          forceToAxis: true,
          invert: true
        },
        slidesPerView: 2,
        spaceBetween: 5,
        centeredSlides: true,
        on: {
          touchEnd () {
            console.log('touchEnd', this.realIndex)
            vue.methods.navigate(this.realIndex)
          }
        }
      },
      methods: {
        navigate (index) {
          console.log(index)
          this.$router.push('/actualites/'+index)
        }
      }
    }
  }
}

Anyone knows how can access to Router in methods ?

This question is available on Nuxt.js community (#c2295)