[Vuejs]-BeforeRouteUpdate not recognizing function

0👍

The concept you want use it, is called "prefetch".
It’s better use this solution:

  beforeRouteEnter(to, from, next) {
    axios.get(
        'http://127.0.0.1:8000/api/word/' + this.$route.params.word,
        {validateStatus: false}
    )
        .then(resp => {
          next()
        })
        .catch(error => {
        })
  },

  beforeRouteUpdate(to, from, next) {
    axios.get(
        'http://127.0.0.1:8000/api/word/' + this.$route.params.word,
        {validateStatus: false}
    )
        .then(resp => {
          next()
        })
        .catch(error => {
        })
  }

NOTE 1: You don’t access to this in beforeRouteEnter (to use methods). Because your component doesn’t mounted yet.

NOTE 2: To avoid fetch duplication (DRY principle), you can modularize fetching (like vuex actions) and call it.

Leave a comment