所属分类:购物车
说明:修复输入框的值验证,对于非正整数,值清空,并在失焦时,值设为0。
代码修改地方:
1 | < input type = "text" class = "num-input" v-model = "item.pro_num" > |
处新增两个判断
1 | @input= "search($event,index)" @blur= "check($event,index)" , |
即
1 | < input type = "text" class = "num-input" v-model = "item.pro_num" @ input = "search($event,index)" @ blur = "check($event,index)" > |
对应methods加两个函数:
1 2 3 4 5 6 7 8 9 10 11 12 | search: function (event, index) { search: function (event, index) { let flag = new RegExp( "^[1-9]([0-9])*$" ).test(event.target.value); if (!flag) { this .productList[index].pro_num = '' ; } }, check: function (event, index) { if (event.target.value == '' ) { this .productList[index].pro_num = 0; } }, |
css
┝ global.css
┝ order.css
images
┝ add.png
┝ minus.png
┝ test1.jpg
┝ test2.jpg
┝ index.html