你最后怎么解决的
样式问题,帮忙看看view与view之间有缝隙,使背景颜色透出[图片] 如图,背景颜色是红色,view与view之间会有缝隙让背景颜色溢出,看着view就会有红色边框一样,模拟器与iphone正常,部分安卓(一加5等) [图片]
2019-07-19我也遇到这个问题了,脑壳疼
哪位大神看看怎么解决[图片] 如图,背景颜色是红色,view与view之间会有缝隙让背景颜色溢出,看着view就会有红色边框一样,模拟器与iphone正常,部分安卓(一加5等) [图片]
2019-07-19用bindinput,触发即可
input输入值改变视图在input输入值后如何更改列表总价格以及总数量,想了好久都没有想出来,请各位大神帮忙解决一下。。。。。。。 这个是商品列表wxml: [代码]<view class="container">[代码] [代码] <[代码][代码]view[代码] [代码]class[代码][代码]=[代码][代码]"goodslist"[代码][代码]>[代码] [代码] [代码][代码]<!--item-->[代码][代码] [代码][代码]<[代码][代码]block[代码] [代码]wx:for[代码][代码]=[代码][代码]"{{goodslist}}"[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]view[代码] [代码]class[代码][代码]=[代码][代码]"goods"[代码][代码]>[代码][代码] [代码][代码]<!--左侧图片盒子-->[代码][代码] [代码][代码]<[代码][代码]view[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]image[代码] [代码]src[代码][代码]=[代码][代码]"{{item.imgUrl}}"[代码] [代码]class[代码][代码]=[代码][代码]"good-img"[代码] [代码]/>[代码][代码] [代码][代码]</[代码][代码]view[代码][代码]>[代码][代码] [代码][代码]<!--右侧说明部分-->[代码][代码] [代码][代码]<[代码][代码]view[代码] [代码]class[代码][代码]=[代码][代码]"good-cont"[代码][代码]>[代码][代码] [代码][代码]<!--上--文字说明-->[代码][代码] [代码][代码]<[代码][代码]view[代码] [代码]class[代码][代码]=[代码][代码]"goods-navigator"[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]text[代码] [代码]class[代码][代码]=[代码][代码]"good-name"[代码][代码]>{{item.name}}</[代码][代码]text[代码][代码]>[代码][代码] [代码][代码]</[代码][代码]view[代码][代码]>[代码][代码] [代码][代码]<!--下--价格部分-->[代码][代码] [代码][代码]<[代码][代码]view[代码] [代码]class[代码][代码]=[代码][代码]"good-price"[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]text[代码][代码]>¥{{item.price}}</[代码][代码]text[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]image[代码] [代码]id[代码][代码]=[代码][代码]"{{item.id}}"[代码] [代码]class[代码][代码]=[代码][代码]"cart"[代码] [代码]src[代码][代码]=[代码][代码]"/images/new_73.jpg"[代码] [代码]bindtap[代码][代码]=[代码][代码]"addcart"[代码] [代码]data-status[代码][代码]=[代码][代码]"0"[代码][代码]/>[代码][代码] [代码][代码]</[代码][代码]view[代码][代码]>[代码][代码] [代码][代码]</[代码][代码]view[代码][代码]>[代码][代码] [代码][代码]</[代码][代码]view[代码][代码]>[代码][代码] [代码][代码]</[代码][代码]block[代码][代码]>[代码][代码] [代码][代码]</[代码][代码]view[代码][代码]>[代码][代码]</[代码][代码]view[代码][代码]>[代码] 这个是商品列表js: [代码]Page({[代码][代码] [代码][代码]data: {[代码][代码] [代码][代码]goodslist: [[代码][代码] [代码][代码]{[代码][代码] [代码][代码]id:[代码][代码]"001"[代码][代码],[代码][代码] [代码][代码]imgUrl:[代码][代码]"http://img5.imgtn.bdimg.com/it/u=2906541843,1492984080&fm=23&gp=0.jpg"[代码][代码],[代码][代码] [代码][代码]name:[代码][代码]"女装T恤中长款大码摆裙春夏新款"[代码][代码],[代码][代码] [代码][代码]price:[代码][代码]"65.00"[代码][代码] [代码][代码]},[代码][代码] [代码][代码]{[代码][代码] [代码][代码]id:[代码][代码]"002"[代码][代码],[代码][代码] [代码][代码]imgUrl:[代码][代码]"http://img4.imgtn.bdimg.com/it/u=1004404590,1607956492&fm=23&gp=0.jpg"[代码][代码],[代码][代码] [代码][代码]name:[代码][代码]"火亮春秋季 男青年修身款圆领男士T恤"[代码][代码],[代码][代码] [代码][代码]price:[代码][代码]"68.00"[代码][代码] [代码][代码]}[代码] [代码] [代码][代码]][代码][代码] [代码][代码]},[代码][代码] [代码][代码]// 加入购物车[代码][代码] [代码][代码]addcart:[代码][代码]function[代码][代码](e){[代码][代码] [代码][代码]this[代码][代码].setData({[代码][代码] [代码][代码]toastHidden:[代码][代码]false[代码][代码] [代码][代码]});[代码][代码] [代码][代码]// 遍历列表 与 购物车列表[代码][代码] [代码][代码]for[代码] [代码]([代码][代码]var[代码] [代码]i [代码][代码]in[代码] [代码]this[代码][代码].data.goodslist){[代码][代码] [代码][代码]// 列表中某一项item的id == 点击事件传递过来的id。则是被点击的项[代码][代码] [代码][代码]if[代码][代码]([代码][代码]this[代码][代码].data.goodslist[i].id == e.target.id){[代码][代码] [代码][代码]// 给goodsList数组的当前项添加count元素,值为1,用于记录添加到购物车的数量[代码][代码] [代码][代码]this[代码][代码].data.goodslist[i].count = 1;[代码] [代码] [代码][代码]// 获取购物车的缓存数组(没有数据,则赋予一个空数组)[代码][代码] [代码][代码]var[代码] [代码]arr = wx.getStorageSync([代码][代码]'cart'[代码][代码]) || [];[代码][代码] [代码][代码]// 如果购物车有数据[代码][代码] [代码][代码]if[代码][代码](arr.length>0){[代码][代码] [代码][代码]// 遍历购物车数组[代码][代码] [代码][代码]for[代码][代码]([代码][代码]var[代码] [代码]j [代码][代码]in[代码] [代码]arr){[代码][代码] [代码][代码]// 判断购物车内的item的id,和事件传递过来的id,是否相等[代码][代码] [代码][代码]if[代码][代码](arr[j].id == e.target.id){[代码][代码] [代码][代码]// 相等的话,给count+1(即再次添加入购物车,数量+1)[代码][代码] [代码][代码]// arr[j].count = arr[j].count + 1;[代码][代码] [代码][代码]// 最后,把购物车数据,存放入缓存(此处不用再给购物车数组push元素进去,因为这个是购物车有的,直接更新当前数组即可)[代码][代码] [代码][代码]try[代码] [代码]{[代码][代码] [代码][代码]wx.setStorageSync([代码][代码]'cart'[代码][代码], arr)[代码][代码] [代码][代码]} [代码][代码]catch[代码] [代码](e) {[代码][代码] [代码][代码]console.log(e)[代码][代码] [代码][代码]}[代码][代码] [代码][代码]// 返回(在if内使用return,跳出循环节约运算,节约性能)[代码][代码] [代码][代码]return[代码][代码];[代码][代码] [代码][代码]}[代码][代码] [代码][代码]}[代码][代码] [代码][代码]// 遍历完购物车后,没有对应的item项,把goodslist的当前项放入购物车数组[代码][代码] [代码][代码]arr.push([代码][代码]this[代码][代码].data.goodslist[i]);[代码][代码] [代码][代码]}[代码][代码] [代码][代码]// 购物车没有数据,把item项push放入当前数据(第一次存放时)[代码][代码] [代码][代码]else[代码][代码]{[代码][代码] [代码][代码]arr.push([代码][代码]this[代码][代码].data.goodslist[i]);[代码][代码] [代码][代码]}[代码][代码] [代码][代码]// 最后,把购物车数据,存放入缓存[代码][代码] [代码][代码]try[代码] [代码]{[代码][代码] [代码][代码]wx.setStorageSync([代码][代码]'cart'[代码][代码], arr)[代码][代码] [代码][代码]// 返回(在if内使用return,跳出循环节约运算,节约性能)[代码][代码] [代码][代码]return[代码][代码];[代码][代码] [代码][代码]} [代码][代码]catch[代码] [代码](e) {[代码][代码] [代码][代码]console.log(e)[代码][代码] [代码][代码]}[代码][代码] [代码][代码]}[代码][代码] [代码][代码]}[代码][代码] [代码][代码]}[代码][代码]})[代码]这个是购物车wxml: [代码]<!--要是够车内没有数据,就行显示没有数据-->[代码][代码]<[代码][代码]view[代码] [代码]class[代码][代码]=[代码][代码]"cart"[代码] [代码]hidden[代码][代码]=[代码][代码]"{{iscart}}"[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]image[代码] [代码]src[代码][代码]=[代码][代码]"/images/cart.png"[代码] [代码]/>[代码][代码] [代码][代码]<[代码][代码]view[代码][代码]>购物车什么都没有,赶快去购物吧</[代码][代码]view[代码][代码]>[代码][代码]</[代码][代码]view[代码][代码]>[代码][代码]<!--要是有数据,就显示数据-->[代码][代码]<[代码][代码]view[代码] [代码]class[代码][代码]=[代码][代码]"cartList"[代码] [代码]hidden[代码][代码]=[代码][代码]"{{!iscart}}"[代码][代码]>[代码][代码] [代码][代码]<!--header-->[代码][代码] [代码][代码]<[代码][代码]view[代码] [代码]class[代码][代码]=[代码][代码]"baoyou"[代码][代码]></[代码][代码]view[代码][代码]>[代码][代码] [代码][代码]<!--list item-->[代码][代码] [代码][代码]<[代码][代码]block[代码] [代码]wx:for[代码][代码]=[代码][代码]"{{cart}}"[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]view[代码] [代码]class[代码][代码]=[代码][代码]"goods"[代码][代码]>[代码][代码] [代码][代码]<!--左侧图片-->[代码][代码] [代码][代码]<[代码][代码]view[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]image[代码] [代码]src[代码][代码]=[代码][代码]"{{item.imgUrl}}"[代码] [代码]class[代码][代码]=[代码][代码]"good-img"[代码] [代码]/>[代码][代码] [代码][代码]</[代码][代码]view[代码][代码]>[代码][代码] [代码][代码]<!--右侧说明部分-->[代码][代码] [代码][代码]<[代码][代码]view[代码] [代码]class[代码][代码]=[代码][代码]"good-cont"[代码][代码]>[代码][代码] [代码][代码]<!--文字说明-->[代码][代码] [代码][代码]<[代码][代码]view[代码] [代码]class[代码][代码]=[代码][代码]"goods-navigator"[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]text[代码] [代码]class[代码][代码]=[代码][代码]"good-name"[代码][代码]>{{item.name}}</[代码][代码]text[代码][代码]>[代码][代码] [代码][代码]</[代码][代码]view[代码][代码]>[代码][代码] [代码][代码]<!--价钱和购物加减的父盒子-->[代码][代码] [代码][代码]<[代码][代码]view[代码] [代码]class[代码][代码]=[代码][代码]"good-price"[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]text[代码] [代码]class[代码][代码]=[代码][代码]"price"[代码][代码]>¥{{item.price}}</[代码][代码]text[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]view[代码] [代码]class[代码][代码]=[代码][代码]"btn-box"[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]view[代码] [代码]class[代码][代码]=[代码][代码]"btn"[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]button[代码] [代码]id[代码][代码]=[代码][代码]"del{{index}}"[代码] [代码]type[代码][代码]=[代码][代码]"default"[代码] [代码]size[代码][代码]=[代码][代码]"mini"[代码] [代码]bindtap[代码][代码]=[代码][代码]"delCount"[代码][代码]>-</[代码][代码]button[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]input[代码] [代码]type[代码][代码]=[代码][代码]"digit"[代码] [代码]maxlength[代码][代码]=[代码][代码]"5"[代码] [代码]value[代码][代码]=[代码][代码]"{{item.count}}"[代码] [代码]bindinput[代码][代码]=[代码][代码]"bindReplaceInput"[代码] [代码]/>[代码][代码] [代码][代码]<[代码][代码]button[代码] [代码]id[代码][代码]=[代码][代码]"add{{index}}"[代码] [代码]type[代码][代码]=[代码][代码]"default"[代码] [代码]size[代码][代码]=[代码][代码]"mini"[代码] [代码]bindtap[代码][代码]=[代码][代码]"addCount"[代码][代码]>+</[代码][代码]button[代码][代码]>[代码][代码] [代码][代码]</[代码][代码]view[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]image[代码] [代码]id[代码][代码]=[代码][代码]"img{{index}}"[代码] [代码]src[代码][代码]=[代码][代码]"/images/del2.png"[代码] [代码]bindtap[代码][代码]=[代码][代码]"delGoods"[代码] [代码]/>[代码][代码] [代码][代码]</[代码][代码]view[代码][代码]>[代码][代码] [代码][代码]</[代码][代码]view[代码][代码]>[代码][代码] [代码][代码]</[代码][代码]view[代码][代码]>[代码][代码] [代码][代码]</[代码][代码]view[代码][代码]>[代码][代码] [代码][代码]</[代码][代码]block[代码][代码]>[代码][代码] [代码][代码]<!--footer-->[代码][代码] [代码][代码]<[代码][代码]view[代码] [代码]class[代码][代码]=[代码][代码]"total"[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]view[代码] [代码]class[代码][代码]=[代码][代码]"total_text"[代码][代码]>合计:[代码][代码] [代码][代码]<[代码][代码]text[代码][代码]>¥{{total}}</[代码][代码]text[代码][代码]>[代码][代码] [代码][代码]</[代码][代码]view[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]button[代码] [代码]class[代码][代码]=[代码][代码]"total_js"[代码] [代码]size[代码][代码]=[代码][代码]"mini"[代码][代码]>去结算({{goodsCount}})</[代码][代码]button[代码][代码]>[代码][代码] [代码][代码]</[代码][代码]view[代码][代码]>[代码][代码]</[代码][代码]view[代码][代码]>[代码]这个是购物车js: [代码]Page({[代码][代码] [代码][代码]data: {[代码][代码] [代码][代码]iscart: [代码][代码]false[代码][代码],[代码][代码] [代码][代码]cart: [], [代码][代码]//数据[代码][代码] [代码][代码]count: 1,[代码][代码] [代码][代码]total: 0, [代码][代码]//总金额[代码][代码] [代码][代码]goodsCount: 0, [代码][代码]//数量[代码][代码] [代码][代码]},[代码][代码] [代码][代码]onLoad: [代码][代码]function[代码] [代码](options) {[代码] [代码] [代码][代码]},[代码][代码] [代码][代码]bindReplaceInput: [代码][代码]function[代码] [代码](e) {[代码][代码] [代码][代码]this[代码][代码].setData({[代码][代码] [代码][代码]count: e.detail.value[代码][代码] [代码][代码]})[代码][代码] [代码][代码]},[代码][代码] [代码][代码]onShow: [代码][代码]function[代码] [代码]() {[代码][代码] [代码][代码]// 获取产品展示页保存的缓存数据(购物车的缓存数组,没有数据,则赋予一个空数组)[代码][代码] [代码][代码]var[代码] [代码]arr = wx.getStorageSync([代码][代码]'cart'[代码][代码]) || [];[代码][代码] [代码][代码]// 有数据的话,就遍历数据,计算总金额 和 总数量[代码][代码] [代码][代码]if[代码] [代码](arr.length > 0) {[代码][代码] [代码][代码]this[代码][代码].data.total = 0;[代码][代码] [代码][代码]this[代码][代码].data.goodsCount = 0;[代码][代码] [代码][代码]for[代码] [代码]([代码][代码]var[代码] [代码]i [代码][代码]in[代码] [代码]arr) {[代码][代码] [代码][代码]this[代码][代码].data.total += Number(arr[i].price) * Number(arr[i].count);[代码][代码] [代码][代码]this[代码][代码].data.goodsCount += Number(arr[i].count);[代码][代码] [代码][代码]}[代码][代码] [代码][代码]// 更新数据[代码][代码] [代码][代码]this[代码][代码].setData({[代码][代码] [代码][代码]iscart: [代码][代码]true[代码][代码],[代码][代码] [代码][代码]cart: arr,[代码][代码] [代码][代码]total: [代码][代码]this[代码][代码].data.total,[代码][代码] [代码][代码]goodsCount: [代码][代码]this[代码][代码].data.goodsCount[代码][代码] [代码][代码]});[代码][代码] [代码][代码]}[代码][代码] [代码][代码]},[代码][代码] [代码][代码]/**输入 */[代码][代码] [代码][代码]inputCount:[代码][代码]function[代码][代码](e){[代码] [代码] [代码][代码]},[代码][代码] [代码][代码]/* 减数 */[代码][代码] [代码][代码]delCount: [代码][代码]function[代码] [代码](e) {[代码][代码] [代码][代码]console.log(e)[代码][代码] [代码][代码]// 获取购物车该商品的数量[代码][代码] [代码][代码]// [获取设置在该btn的id,即list的index值][代码][代码] [代码][代码]if[代码] [代码]([代码][代码]this[代码][代码].data.cart[e.target.id.substring(3)].count <= 1) {[代码][代码] [代码][代码]return[代码][代码];[代码][代码] [代码][代码]}[代码][代码] [代码][代码]// 商品总数量-1[代码][代码] [代码][代码]this[代码][代码].data.goodsCount -= 1;[代码][代码] [代码][代码]// 总价钱 减去 对应项的价钱单价[代码][代码] [代码][代码]this[代码][代码].data.total -= Number([代码][代码]this[代码][代码].data.cart[e.target.id.substring(3)].price);[代码][代码] [代码][代码]// 购物车主体数据对应的项的数量-1 并赋给主体数据对应的项内[代码][代码] [代码][代码]this[代码][代码].data.cart[e.target.id.substring(3)].count = --[代码][代码]this[代码][代码].data.cart[e.target.id.substring(3)].count;[代码][代码] [代码][代码]// 更新data数据对象[代码][代码] [代码][代码]this[代码][代码].setData({[代码][代码] [代码][代码]cart: [代码][代码]this[代码][代码].data.cart,[代码][代码] [代码][代码]total: [代码][代码]this[代码][代码].data.total,[代码][代码] [代码][代码]goodsCount: [代码][代码]this[代码][代码].data.goodsCount[代码][代码] [代码][代码]})[代码][代码] [代码][代码]// 主体数据重新赋入缓存内[代码][代码] [代码][代码]try[代码] [代码]{[代码][代码] [代码][代码]wx.setStorageSync([代码][代码]'cart'[代码][代码], [代码][代码]this[代码][代码].data.cart)[代码][代码] [代码][代码]} [代码][代码]catch[代码] [代码](e) {[代码][代码] [代码][代码]console.log(e)[代码][代码] [代码][代码]}[代码][代码] [代码][代码]},[代码][代码] [代码][代码]/* 加数 */[代码][代码] [代码][代码]addCount: [代码][代码]function[代码] [代码](e) {[代码][代码] [代码][代码]// 商品总数量+1[代码][代码] [代码][代码]this[代码][代码].data.goodsCount += 1;[代码][代码] [代码][代码]// 总价钱 加上 对应项的价钱单价[代码][代码] [代码][代码]this[代码][代码].data.total += Number([代码][代码]this[代码][代码].data.cart[e.target.id.substring(3)].price);[代码][代码] [代码][代码]// 购物车主体数据对应的项的数量+1 并赋给主体数据对应的项内[代码][代码] [代码][代码]this[代码][代码].data.cart[e.target.id.substring(3)].count = ++[代码][代码]this[代码][代码].data.cart[e.target.id.substring(3)].count;[代码][代码] [代码][代码]// 更新data数据对象[代码][代码] [代码][代码]this[代码][代码].setData({[代码][代码] [代码][代码]cart: [代码][代码]this[代码][代码].data.cart,[代码][代码] [代码][代码]total: [代码][代码]this[代码][代码].data.total,[代码][代码] [代码][代码]goodsCount: [代码][代码]this[代码][代码].data.goodsCount[代码][代码] [代码][代码]})[代码][代码] [代码][代码]// 主体数据重新赋入缓存内[代码][代码] [代码][代码]try[代码] [代码]{[代码][代码] [代码][代码]wx.setStorageSync([代码][代码]'cart'[代码][代码], [代码][代码]this[代码][代码].data.cart)[代码][代码] [代码][代码]} [代码][代码]catch[代码] [代码](e) {[代码][代码] [代码][代码]console.log(e)[代码][代码] [代码][代码]}[代码][代码] [代码][代码]},[代码][代码] [代码][代码]/* 删除item */[代码][代码] [代码][代码]delGoods: [代码][代码]function[代码] [代码](e) {[代码][代码] [代码][代码]// 商品总数量 减去 对应删除项的数量[代码][代码] [代码][代码]this[代码][代码].data.goodsCount = [代码][代码]this[代码][代码].data.goodsCount - [代码][代码]this[代码][代码].data.cart[e.target.id.substring(3)].count;[代码][代码] [代码][代码]// 总价钱 减去 对应删除项的单价*数量[代码][代码] [代码][代码]this[代码][代码].data.total -= [代码][代码]this[代码][代码].data.cart[e.target.id.substring(3)].price * [代码][代码]this[代码][代码].data.cart[e.target.id.substring(3)].count;[代码][代码] [代码][代码]// 主体数据的数组移除该项[代码][代码] [代码][代码]this[代码][代码].data.cart.splice(e.target.id.substring(3), 1);[代码][代码] [代码][代码]// 更新data数据对象[代码][代码] [代码][代码]this[代码][代码].setData({[代码][代码] [代码][代码]cart: [代码][代码]this[代码][代码].data.cart,[代码][代码] [代码][代码]total: [代码][代码]this[代码][代码].data.total,[代码][代码] [代码][代码]goodsCount: [代码][代码]this[代码][代码].data.goodsCount[代码][代码] [代码][代码]})[代码][代码] [代码][代码]// 主体数据重新赋入缓存内[代码][代码] [代码][代码]try[代码] [代码]{[代码][代码] [代码][代码]wx.setStorageSync([代码][代码]'cart'[代码][代码], [代码][代码]this[代码][代码].data.cart)[代码][代码] [代码][代码]} [代码][代码]catch[代码] [代码](e) {[代码][代码] [代码][代码]console.log(e)[代码][代码] [代码][代码]}[代码][代码] [代码][代码]}[代码] [代码]})[代码]
2019-05-06