vue3 中文文档 去进行详细了解
1.vue2.x 获取dom
1 <div ref="dom"></div> 2 3 this.$refs.dom
2.vue3.x 获取dom
setRef setRef
1 <template> 2 <div :ref="dom">DOM元素</div> 3 </template> 4 5 <script> 6 import { nextTick } from 'vue'; 7 export default { 8 setup() { 9 let refs = ''; 10 11 const dom = el => { 12 refs= el; 13 } 14 15 nextTick(() => { 16 console.log(refs); 17 }) 18 return { 19 dom 20 }; 21 } 22 }; 23 </script>
这样就可以进行dom操作了,有不对的地方欢迎大家指正吖