
请问左上角那个因为在九月份,所以自动显示是九月预算的,是怎么做到的呢?麻烦能用代码讲讲吗
关注
index.wxml
<view>{{currentMonth}}月总预算</view>
index.js
Page({
data: {
currentMonth: ""
},
onLoad() {
// 获取当前月(注意:返回数值为0~11,需要自己+1来显示)
let currentMonth = new Date().getMonth() + 1;
// 补零
currentMonth = (currentMonth < 10 ? '0' : '') + currentMonth
this.setData({ currentMonth })
},
})