undefinedfix
Sign in

After Vue refers to the property of this. $route in data, this$ options.data () missing issues

Silverspur edited in Sun, 12 Jun 2022

After Vue refers to the property of this. $route in data, this$ options.data () missing issues

Please look at the following three pictures. There is also this problem in my own project. Then I built a new project with Vue cli 3. The creation options are all by default, and only Vue router is additionally installed. Is this my problem or the bug of Vue router. Xnip2018-12-29_ 22-11-05.jpgXnip2018-12-29_ 22-11-58.jpgXnip2018-12-29_ 22-12-39.jpg

code

<template>
  <div style="text-align:center">
    <input type="button"
           @click="getData"
           value="测试">
  </div>
</template>

<script>
export default {
  name: "home",
  data() {
    return {
      a: 1,
      b: this.$route
    }
  },
  methods: {
    getData() {
      return this.a
    }
  }
}
</script>
2 Replies
Brendan
commented on Sun, 12 Jun 2022

Test the following code:

data() {
      return {
        a: 1,
        b:router.options.routes
      }
    },

console.log (this.$ options.data ()); print result {A: 1, B: array (5)}

zkuir
commented on Sun, 12 Jun 2022

bookId: parseInt(this.$ route.params.id ),

lock This question has been locked and the reply function has been disabled.