在 Vue3 中,怎么使用 $refs 访问元素引用的方法。Vue2 中相比有所不同,直接使用
this.$refs["refTable"]
给我一个实例,在 Vue3 中使用 refs 来访问elementui-plus的 组件的实例
在 Vue3 中,怎么使用 $refs 访问元素引用的方法。Vue2 中相比有所不同,直接使用
this.$refs["refTable"]
给我一个实例,在 Vue3 中使用 refs 来访问elementui-plus的 组件的实例
<template>
<el-table
ref="multipleTableRef"
:data="tableData"
style="width: 100%"
@selection-change="handleSelectionChange"
>
<!-- 省略表格列的定义 -->
</el-table>
</template>
<script>
import { ref } from 'vue'
export default {
setup() {
const multipleTableRef = ref(null)
// 访问表格组件实例
function submit() {
const table = multipleTableRef.value
// do something with the table instance
}
return {
multipleTableRef,
submit
}
}
}
</script>