<List ref="listEle"></List>
<script setup>
import { reactive, ref, onMounted } from "vue";
const listEle = ref(null)
onMounted(() => {
console.log(listEle.value, 'lll');
})
</script>
在script setup标签里面获取ref绑定的元素,一直获取不到。在网上也找不到其他方法了
版本问题
没有return
<script setup>
import { reactive, ref, onMounted } from "vue";
const listEle = ref(null)
onMounted(() => {
console.log(listEle.value, 'lll');
})
return {
listEle
}
</script>
需要在组件List中将需要的获取的值暴露出去:
<template>
<div class="List" ref="dom">List组件</div>
</template>
<script setup>
import { ref } from "vue";
let value1 = ref(9527);
let dom = ref(null);
const handleFuntion = () => {
console.log(value1.value);
};
defineExpose({ dom, value1, handleFuntion });
</script>