vue 使用ref操作dom

<!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>
posted @ 2019-07-08 13:31  一只大鹅  阅读(2908)  评论(0编辑  收藏  举报