Skip to content
欢迎扫码关注公众号

微信小程序刷新前一页面

场景

从列表页跳转到在新页面,新增一条记录后,返回前页并自动刷新列表。

参考

微信小程序之更新上一页数据 (十二)

实现

  1. 在列表定义一个变量 isNeedRefresh 用来标志是否需要刷新

  2. 在新增页面新增记录后更新前页(即列表页)的标志位。

    js
    // 获取页面栈
    var pages = getCurrentPages();
    if(pages.length > 1){
        // 上一个页面实例对象
        var prePage = pages[pages.length - 2];
        // 关键在这里
        prePage.setData({
            isNeedRefresh: true
        })
    }
  3. 在列表页的 onShow 方法中根据该标志决定是否刷新

    js
    onShow: function () {
        const self = this
        if (self.data.isNeedRefresh) {
          // 调用刷新方法
            self.refresh()
            self.setData({
                isNeedRefresh: false
            })
        }
    }

Page Layout Max Width

Adjust the exact value of the page width of VitePress layout to adapt to different reading needs and screens.

Adjust the maximum width of the page layout
A ranged slider for user to choose and customize their desired width of the maximum width of the page layout can go.

Content Layout Max Width

Adjust the exact value of the document content width of VitePress layout to adapt to different reading needs and screens.

Adjust the maximum width of the content layout
A ranged slider for user to choose and customize their desired width of the maximum width of the content layout can go.