vue 赋值优化

 1       onInput(value) {
 2         // if (this.type == 'payPwd' && this.payPwd.length < 6) {
 3         //   this.payPwd = this.payPwd + value;
 4         // } else if (this.type == 'confirmPayPwd' && this.confirmPayPwd.length < 6) {
 5         //   this.confirmPayPwd = this.confirmPayPwd + value;
 6         // }
 7 
 8         //简化
 9         if (this[this.type].length < 6) {
10           this[this.type] = this[this.type] + value;
11         }
12 
13       },
 1       focus(type) {
 2         // 切换时清除值
 3         // if (type == 'payPwd') {
 4         //   this.payPwd = '';
 5         // } else if (type == 'confirmPayPwd') {
 6         //   this.confirmPayPwd = '';
 7         // }
 8 
 9         //简化
10         this[type] = '';
11       },
原文地址:https://www.cnblogs.com/zhuyujie/p/14212165.html