admin管理员组文章数量:1640614
<button ref="btn">按钮</button>
最好不要使用this.$refs.btn.setAttribute('disabled',true);禁用按钮
因为这个的效果和this.$refs.btn.setAttribute('disabled',false);是一样的,都禁用按钮了,因为true或者false被转化为了字符串,而这个字符串基本等效于true,也就是都是禁用的写法
而若是改为this.$refs.btn.disabled = true(禁用按钮),this.$refs.btn.disabled = false(可用按钮)就能满足正常的需求了
不过非要使用setAttribute也不是不行,要取消禁用按钮就要配合removeAttribute使用了:
this.$refs.btn.removeAttribute('disabled');
vue不太建议使用dom,所以当然在标签中写啦, :disabled=flag(注意flag不要加引号,flag在data中设为Boolean值)
版权声明:本文标题:vue中使用js控制button的disabled属性 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dongtai/1729320557a1195830.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论