Using the v-if Times to mistakenly say that variables are not defined

I"m going to get a favorites button to control the value of collected through the click event, so that v-if can display different pictures according to the value of collected

//

<div class="option collect" @click="collect()">
  <img src="../assets/images/favor_fill.png" v-if="collected">
  <img src="../assets/images/favor2.png" v-else>
  <span></span>
</div>

date () {
  return {
    collected:false
  }
},
methods: {
  collect:function() {
    this.collected = !this.collected
  }
}

when I execute the above code, there will be the following error:

means that my collected is not defined, but I clearly defined it in data. If I define collected in created, there will be no error:

created() {
      this.collected = false
    }

so I guess the variables in data haven"t actually been defined when v-if works, so v-if has no idea what collected is. I don"t know if my guess is correct. And no matter how the value of collected changes, it always shows the picture of v-else. Is it because v-if only judges the value of collected once? How to change the code to realize the function of favorites button


data, date?


clipboard.png

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eb11c1-48104.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eb11c1-48104.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?