Using $refs in a computed property

后端 未结 6 1250
后悔当初
后悔当初 2020-12-25 09:02

How do I access $refs inside computed? It\'s always undefined the first time the computed property is run.

6条回答
  •  既然无缘
    2020-12-25 09:41

    I think it is important to quote the Vue js guide:

    $refs are only populated after the component has been rendered, and they are not reactive. It is only meant as an escape hatch for direct child manipulation - you should avoid accessing $refs from within templates or computed properties.

    It is therefore not something you're supposed to do, although you can always hack your way around it.

提交回复
热议问题