整数乘法。实现两个输入框(input),用于乘数输入;一个按钮(button)用于确认计算;view组件用于显示计算结果。并将乘数及计算结果上传至云数据库中(云数据库collection名称为result)。
示例: 即表示此input组id为input1
要求:
a. 页面应为question1,pages/question1即如下图
b. 两个输入框(input)id一个为input1,一个为input2;按钮id为submit;view组件id为result。
c. 展示多个乘法计算示例
d. (选做)云函数实现整数乘法
<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>
const db = wx.cloud.database()
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
}, () => {
db.collection('result').add({
// data 字段表示需新增的 JSON 数据
data: {
resultList
},
success: function(res) {
// res 是一个对象,其中有 _id 字段标记刚创建的记录的 id
console.log(res)
}
})
})
}
},
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;
}
这个不难呢,你是没思路还是什么呢?
xs,应该是一个教室里考试的同学了