vue實(shí)例的屬性和方法
var vm=new Vue({
// el:'#itany',
data:{
msg:'welcome to itany'
},
name:'tom',
age:24,
show:function(){
console.log('show');
}
});
屬性? ? vm.屬性名 獲取data中的屬性
console.log(vm.msg);? //在外面打印出來(lái)屬性
vm.$el? ? 獲取vue實(shí)例關(guān)聯(lián)的元素
console.log(vm.$el);//DOM對(duì)象
vm.$el.style.color='red';
vm.$data? //獲取數(shù)據(jù)對(duì)象data
console.log(vm.$data);
console.log(vm.$data.msg);
vm.$options//獲取自定義屬性.方法
console.log(vm.$options.name);
console.log(vm.$options.age);
vm.$options.show();
vm.$refs 獲取所有添加ref屬性的元素
console.log(vm.$refs);
console.log(vm.$refs.hello);? ?//DOM對(duì)象
vm.$refs.hello.style.color='blue';
vm.$refs.hello? ? ? //獲取一個(gè)標(biāo)簽? 和需要在頁(yè)面上定義ref="hello"
vm.$refs.hello.textContent? ? ?//獲取標(biāo)簽里面的文本(如果去獲取修改了過后的值,是獲取不了的)
//DOM還沒更新完,Vue實(shí)現(xiàn)響應(yīng)式并不是數(shù)據(jù)發(fā)生改變之后DOM立即變化,需要按一定的策略進(jìn)行DOM更新,需要時(shí)間??!
vm.$nextTick(function(){
? ? ? //DOM更新完成,更新完成后再執(zhí)行此代碼
console.log(vm.$refs.title.textContent);
});
vm.$refs.hello.style.color="blue"? // 修改標(biāo)簽里面的顏色