如何将上一个页面setStorage的值取出放入新页面的data?
发布于 5 年前 作者 qiang47 3467 次浏览 来自 问答

RT,我在B页面的JS中getStorage了A页面储存的值,并且能够打印出来,但是放入data中页面显示为undefined。请问这是怎么回事呢?

下面是我的B页面的部分JS。

Page({
    data:{
        location: '',
        items: [
            { name: 'benDi', value: '' + location },
          { name: 'waiDi', value: '非' + location },
        ]
    },
    onload:function (options) {
        var that = this;
        wx.getStorage({
            key: 'location',
            success (res) {
                console.log(res.data)
                that.setData({
                    location: res.data    
                })
            }
        })
    }
})
1 回复

麻烦提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。

给下WXML代码看看。

回到顶部