Page({
data: {
num: 1,
cart: [],
total: 20,
price: 20,
},
// 相加
upup: function () {
this.data.num += 1;
this.data.total = Number(this.data.num) * this.data.price,
// 将其赋值
this.setData({
num: this.data.num,
total: this.data.total
})
},
// 相减
dndn: function () {
if(this.data.num<=1){
return;
}
this.data.num -= 1;
this.data.total = Number(this.data.num) * this.data.price,
// 将其赋值
this.setData({
num: this.data.num,
total: this.data.total
})
},
// 页面跳转与赋值
letGo: function () {
wx.setStorageSync('total', this.data.total)
wx.setStorageSync('num', this.data.num)
wx.navigateTo({
url: '../logs/logs'
})
},
})
Page({
data: {
},
// onload时接收页面与获取缓存并且赋值
onLoad: function (options) {
var arr = wx.getStorageSync('total');
var num = wx.getStorageSync('num');
var gods = wx.setStorageSync('gods');
this.setData({
total: arr,
num: num,
gods:gods
});
},
})