vue 使用ref操作dom

mac2022-06-30  11

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <script src="https://cdn.bootcss.com/vue/2.6.10/vue.js"></script> <body> <div id="app"> <h3 ref="myh3">{{name}}</h3> </div> <script> var vm = new Vue({ el:'#app', data:{ name:'1' }, methods: {   }, mounted () { this.$refs.myh3.style.color='red' } }); </script> </body> </html>

转载于:https://www.cnblogs.com/xiannv/p/11150659.html

最新回复(0)