Vue.js computed property not updating

前端 未结 7 803
猫巷女王i
猫巷女王i 2020-12-29 22:36

I\'m using a Vue.js computed property but am running into an issue: The computed method IS being called at the correct times, but the value returned by the computed

7条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-29 22:55

    If you add console.log before returning, you may be able to see computed value in filteredClasses.

    But DOM will not updated for some reason.

    Then you need to force to re-render DOM.

    The best way to re-render is just adding key as computed value like below.

    Caution:

    Don’t use non-primitive values like objects and arrays as keys. Use string or numeric values instead.

    That is why I converted array filteredClasses to string. (There can be other array->string convert methods)

    And I also want to say that "It is recommended to provide a key attribute with v-for whenever possible".

提交回复
热议问题