vue项目中点击打开弹窗,弹窗上面有子组件,在点击打开弹窗的方法中使用this.$refs却获取不到子组件的ref值:

 

简易代码如下: 

<a-modal centered v-model="visible" :title="title">
   <upload ref="upload" />
</a-modal>

js:


        handleOpenUpload(){
            this.visibleUpload = true;
            console.log('refs',this.$refs.upload); //获取不到
        }

解决:

handleOpenUpload(){
            this.visibleUpload = true;
            this.$nextTick(() => {
                console.log('refs',this.$refs.upload);//能获取
            });
        }

 

Logo

前往低代码交流专区

更多推荐