html
<view class="box">
<text>日期:</text>
<view class="date">{{obtaindate}}</view>
</view>
wxml中定义了一个文本元素,通过{{obtaindate}}获取js页面传递的日期数据
javascript
data:{
obtaindate:""
},
onload:function(){
let date= new Date;
let year = date.getfullYear();
let mounth = date.getmounth();
let day = date.getday();
let obtaindate = "$year-$mounth-$day";
this.setDate({
obtaindate:obtaindate
});
},
js页面中定义了一个date,通过该对象获取年月日,并将其拼接起来,通过this.setDate方法将拼接好的日期写入页面中
运行结果如下