获取单个Dom
<input type="text" ref="inputRef" /> setup() { const inputRef = ref(null) onMounted(()=>{ console.log(inputRef.value); }) }
获取多个Dom
<div v-for="(item, index) in state.list" :key="index" :ref="setItemRef"> {{item}} </div> setup() { let itemRef = ref([]) let state = reactive([]) const setItemRef = (el) => { itemRef.value.push(el) } onMounted(()=>{ // 模拟调用接口 setTimeout(()=>{ state.curMenuList = [1,2,3] },1000) }) onBeforeUpdate(() => { itemRef.value = []; }); onUpdated(()=>{ itemRef.value.map(d=>{ d.style.height = '100px' }) }) return { state, setItemRef, } }
标签:itemRef,Dom,value,获取,state,vue3,ref From: https://www.cnblogs.com/lftBlogs/p/18029168