vue中DOM的获取
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="">
<script src="vue/vue.js"></script>
<script src="vue/vue-router.js"></script>
</head>
<body>
<!--[if lt IE 7]>
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="#">upgrade your browser</a> to improve your experience.</p>
<![endif]-->
<div id="app">
<button v-on:click='dianji'>点击获取Dom元素</button>
<p ref='yuansheng'>我是原生</p>
<one ref='zujian'></one>
</div>
<!-- vue中的DOM获取操作
1、用ref属性在想获取元素上进行绑定(ref = '自定义名')
2、在vue实例中,通过this.$refs.自定义名,进行获取
3、对获取的DOM进行操作
-->
<template id="one">
<div>
我是组件
</div>
</template>
<script>
var one = {
data:function(){
return{
};
},
template:'#one',
};
var app = new Vue({
el:'#app',
data:{},
components:{
'one':one,
},
methods:{
dianji:function(){
console.log(this.$refs.yuansheng);
console.log(this.$refs.zujian);
}
}
})
</script>
</body>
</html>