Why does my Vue component require :key?

后端 未结 4 1181
渐次进展
渐次进展 2020-12-11 18:16

I have a small Vue.js component which displays a favorite star icon. Clicking on the icon favorites/unfavorites the element. So far I have only implemented the UI part, whic

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-11 18:30

    You shouldn't need the :key, it's only necessary in v-for loops. I would suggest you remove it and replace your v-show with a v-if and v-else directive.

      
      
    

    v-if removes and addes the section to the DOM whereas v-show just hides it so this way well resolve your issue

提交回复
热议问题