1. <!DOCTYPE html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8">
    5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
    6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
    7. <title>Document</title>
    8. <script src="./lib/vue.js"></script>
    9. </head>
    10. <body>
    11. <div id="app">
    12. <input type="button" @click="get" value="获取元素">
    13. <h3 ref="myh3">哈哈哈,我是一个h3</h3>
    14. </div>
    15. <script>
    16. var vm=new Vue({
    17. el:'#app',
    18. data:{},
    19. methods:{
    20. get(){
    21. alert(this.$refs.myh3.innerText)
    22. }
    23. }
    24. });
    25. </script>
    26. </body>
    27. </html>

    2.gif