1.通过标签属性data来绑定data中的参数key
2.通过bandinput获取key值
3.通过模板字符串赋值给data中的值
wxml:
<view class="row">
<view class="label">产品名称</view>
<view class="value">
<input value="{{ goodsName }}" bindinput="bindKeyInput" data-params="goodsName" placeholder='请填写产品名称' placeholder-class='placeholder' />
</view>
</view>
<view class="row">
<view class="label">产品价格</view>
<view class="value">
<input value="{{ goodsPrice }}" type="digit" bindinput="bindKeyInput" data-params="goodsPrice" placeholder='请填写产品价格' placeholder-class='placeholder' />
</view>
</view>
js:
data: {
goodsName:"",
goodsPrice:"",
},
bindKeyInput(e){
console.log(e)
this.setData({
[`${e.currentTarget.dataset.params}`]:e.detail.value
})
console.log(`商品名称:${this.data.goodsName},商品价格:${this.data.goodsPrice}`)
},