Vue3中 如何使用ref标签,对组件进行操作

在Vue2中 一般用 this.$ref.xxxx 进行获取组件对象
Vue3中就不使用这个方法了
例如:

     <el-upload class="upload-demo" action="" :http-request="handleUpload" 
                    :on-change="handleChange"
          :before-upload="handleBeforeUpload" :show-file-list="false" :auto-upload="false" :limit="1" ref="uploadRef">
          <el-button type="primary" icon="upload" slot="trigger">导入</el-button>
        </el-upload>

想要获取el-upload组件对象

先创建

const uploadRef =  ref()

使用的话需要xxx.value.xxx
例如:

  // 清除上传列表
  uploadRef.value.clearFiles()

posted @ 2023-04-17 14:26  knva  阅读(144)  评论(0编辑  收藏  举报