以 antd vue 为例
主要就是这句代码: proxy.$refs.input.select();
其实就是调用select()方法
<template>
<a-input ref="input" v-model:value="newFileName" />
<div class="add_file" @click="addNewFileFun">新建文件夹</div>
</template>
<script>
import { defineComponent, ref, reactive, getCurrentInstance } from 'vue';
export default defineComponent({
setup(props, context) {
const {proxy} = getCurrentInstance();
const newFileName = ref('');
const addNewFileFun = ()=>{
newFileName.value = '未命名的文件夹';
proxy.$nextTick(()=>{
proxy.$refs.input.select();
})
}
return{
newFileName,
addNewFileFun,
}
}
});
</script>