vue3 ref获取dom节点

<script setup>
import { ref ,getCurrentInstance,nextTick} from 'vue'
import Header from './Header.vue'

const {proxy} = getCurrentInstance()

const rename = ref(null)//声明一个和ref一样的名字,直接获取它


nextTick(()=>{
  console.log(rename.value)



  //console.log(proxy.$refs.rename) 或者直接这样获取
    //要获取子组件的dom节点,通过绑定ref在子组件标签上,子组件获取自己的dom节点,通过defineExpose暴露给父组件
})
</script>


<template>
  <div ref="rename"></div>
  <Header/>
  <div></div>
</template>




你可能感兴趣的:(vue3,vue.js,javascript,前端)