当组件有初始数据时 setData 不能工作
使用 wepy 1.7.0 创建的项目。当组件有初始数据 time: 0,setData 将 time 更新后,立即又会变回 0。期望 time 是 setData 更新后的值。 [代码]<template>[代码][代码] [代码][代码]<page>[代码][代码] [代码][代码]<view class="weui-cells">[代码][代码] [代码][代码]<view class="weui-cell">[代码][代码] [代码][代码]<view class="weui-cell__bd">当前时间</view>[代码][代码] [代码][代码]<view class="weui-cell__ft">{{time}}</view>[代码][代码] [代码][代码]</view>[代码][代码] [代码][代码]</view>[代码][代码] [代码][代码]<view class="page__bd page__bd_spacing" style="padding-top:15px">[代码][代码] [代码][代码]<button class="weui-btn" type="primary" @tap="getTime">异步获取当前时间</button>[代码][代码] [代码][代码]</view>[代码][代码] [代码][代码]</page>[代码][代码]</template>[代码][代码]<script>[代码][代码] [代码][代码]import wepy from 'wepy'[代码] [代码] [代码][代码]export default class NoRedux extends wepy.page {[代码][代码] [代码][代码]data = {[代码][代码] [代码][代码]time: 0[代码][代码] [代码][代码]}[代码][代码] [代码][代码]getTime() {[代码][代码] [代码][代码]this.setData({ time: Date.now() })[代码][代码] [代码][代码]}[代码][代码] [代码][代码]}[代码][代码]</script>[代码] 1. setData 调用前 $data, $initData 的 time 均为 0 [图片] 2. setData 调用后,$data.time 被更新 [图片] 3. 退出事件处理函数 $data.time 变为 0 [图片]