- 大概是这样子,一些小细节自己去改一下就好,有帮助麻烦点个采纳【本回答右上角】
<input type="number" id="input1" bindinput="handleInput1" value="{{input1}}"/> *
<input type="number" id="input2" bindinput="handleInput2" value="{{input2}}"/> =
<button bindtap="calculate">计算</button>
<view id="result">
<view wx:for="{{resultList}}">{{item}}</view>
</view>
Page({
data: {
result: [],
input1: '',
input2: '',
},
onLoad: function () {
console.log('Welcome to Mini Code')
},
calculate: function () {
const { input1, input2,resultList } = this.data
if (input1 === '' || input2 === '') {
wx.showToast({
title: '请输入正确的数字',
duration: 2000,
icon: 'warning'
});
} else {
resultList.push(`${input1} * ${input2} = ${input1 * 1 * input2}`)
this.setData({
resultList
}, () => {
wx.cloud.callFunction({
name: 'result',
data: resultList
}).then(console.log)
})
}
},
handleInput1: function (e) {
this.setData({
input1: e.detail.value
})
},
handleInput2: function (e) {
this.setData({
input2: e.detail.value
})
}
})
input {
border: 1px solid;
display: inline-block;
width: 100pt;
}