ref-获取dom

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
    <script src="../js/vue.js"></script>
    <style>
 
    </style>

</head>
<body>
   
    <div id="root"></div>
     
    <script>  
        // ref-获取dom 节点
       var app = Vue.createApp({    
            setup(){  
                const {ref,onMounted} = Vue
                const hello = ref(null)
                onMounted(()=>{
                    console.log(hello.value);
                })
                return { hello }
            },

            template:`  
                <div>
                    <div ref="hello"> hello world </div>  
                </div>  
            `
        })
        app.mount('#root')

    </script>

</body>
</html>
posted @ 2021-12-14 14:08  13522679763-任国强  阅读(17)  评论(0)    收藏  举报