小程序数量组件

wxml文件

<view class="numberBox">
	<view class="reduce" bindtap="reduce">-</view>
	<input class="num" bindblur="numFn" value="{{num}}" type="number"/>
	<view class="plus" bindtap="plus">+</view>
</view>

wxss文件

.numberBox{
	width: 130rpx;
	height: 40rpx;
	line-height: 40rpx;
	text-align: center;
	display: flex;
	align-items: center;
	justify-content: space-between;
	border: 2rpx solid #ccc;
	border-radius: 20rpx;
}
.numberBox .reduce,
.numberBox .plus{
	width: 40rpx;
	font-size: 24rpx;
	color: #999;
}
.numberBox .num{
	width: 46rpx;
	height: 40rpx;
	color: #333;
	font-size: 24rpx;
	line-height: 40rpx;
	text-align: center;
	border-left: 2rpx solid #ccc;
	border-right: 2rpx solid #ccc;
}

json文件

{
	"component": true,
	"usingComponents": {}
}

js文件

// component/number/number.js
Component({
	/**
	 * 组件的属性列表
	 */
	properties: {
    num: {
      type: Number,
      value: 1
		},
		type: {
			type: Number,
			value: 1
		},
		bigI: {
			type: String,
			value: ''
		},
		i: {
			type: String,
			value: ''
		}
	},
	data: {
		
	},
	methods: {
		//加
		plus(){
			let num = this.data.num * 1;
			num++;
			this.setData({
				num
			},()=>{
        this.exportNum(1);
      })
		},
		//减
		reduce(){
			let num = this.data.num * 1;
			num--;
			if(num<1){
				num = 1;
				wx.showToast({
					title: '商品数量不能再减少了~',
					icon: 'none',
					duration: 3000
				})
			}
			this.setData({
				num
			},()=>{
        this.exportNum(2);
      })
		},
		//输入
		numFn(e){
			console.log(e);
			this.setData({
				num: e.detail.value*1
			},()=>{
        this.exportNum(3);
      })
		},
		exportNum(types){
			let {num, type, bigI, i} = this.data;
			if(type==1){
				this.triggerEvent('numFn',num)
			}else{
				this.triggerEvent('numFn',{num,bigI,i,types})
			}
		}
	}
})

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值