A页面跳转B页面,B页面中的自定义组件传值不能正确渲染
A页面跳转B页面:
<view>
<navigator url=“/B”>点击这里跳转详情</navigator>
</view>
B页面引入自定义组件:
<view style=“color:red;”>
<theComponent shijianchuo=“{{ secondDiff }}”></theComponent>
</view>
(B页面中的secondDiff是在B页面onLoad中调用接口之后传回的值)
第定义组件wxml:
<view>{{ theTime }}</view>
自定义组件js:
properties: {
shijianchuo: String
},
data: {
theTime: ‘’
},
attached:function(){
const aaa = this.data.shijianchuo
this.setData({
theTime: this.format(aaa)
})
},
methods: {
//计算秒差
format: function (time) {
if (time < 60) {
return time = “时间少于60秒”;
} else {
const minute = parseInt(time / 60);
const hour = parseInt(time / 3600);
const day = parseInt(time / 86400);
if (minute > 60) {
if (hour > 24) {
if (day > 3) {
return time = “3天前”
} else {
return time = `${day}天前`
}
} else {
return time = `${hour}小时前`
}
} else {
return time = `${minute}分钟前`
}
}
}
}
出现问题:在B页面中,秒差未能计算
