Using $refs in a computed property

后端 未结 6 1176
后悔当初
后悔当初 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:47

    For others users like me that need just pass some data to prop, I used data instead of computed

    Vue.component('my-component', {
        data(){
            return {
                myProp: null
            }
        },    
        mounted(){
            this.myProp= 'hello'    
            //$refs is available              
            // this.myProp is reactive, bind will work to property
        }
    })
    

提交回复
热议问题