使用refs的目的:減少操作原生dom,獲取一些dom中的數(shù)據(jù)
eg:<input ref='item' type='text'>
? ? ? ? 想要獲取input中的值
? ? ? ? console.log(this.$refs.item.value);
(PS:$refs不能在created中使用,因為在組件創(chuàng)建時,ref還未綁定元素)
使用refs的目的:減少操作原生dom,獲取一些dom中的數(shù)據(jù)
eg:<input ref='item' type='text'>
? ? ? ? 想要獲取input中的值
? ? ? ? console.log(this.$refs.item.value);
(PS:$refs不能在created中使用,因為在組件創(chuàng)建時,ref還未綁定元素)