微信小程序之点击取消,返回上页,修改上页的参数值,let pages=getCurrentPages() let prevPage=pages[pages.length - 2] // 上一页的数据

实现功能:

个人中心:
在这里插入图片描述
待追访列表:
在这里插入图片描述
待追访详情页:
在这里插入图片描述
1.其他页面返回 个人中心页,需重新获取数据,更新页面内容;
2.待追访详情页,填写追访后,点返回,回到待追访列表,重新获取数据,更新待追访列表数据。

代码实现:

1.个人中心页:

<view class="iconbox" bindtap="daizhuifang">
	<image class="iconimg" mode="widthFix" src="../../images/kehuxitong/xsicon04.png" />
	<view class="icontxt">待追访</view>
	<view class="daizhuikh" wx:if="{
     
     {daizhuikh}}">{
   
   {daizhuikh}}</view>  <!-- 这里是显示的未读数字 -->
</view>
	/**
     * 生命周期函数--监听页面显示
     */
    // onLoad页面加载时调用,可以获取参数,通过options。
	// onShow页面显示时调用。
    onShow: function() {
    
     //页面显示就刷新一下更新数据;
        // console.log(this.data.token);
        // console.log(this.data.type);

        wx.showLoading({
    
    
            title: '加载中...',
            mask: true,
        })
        this.getcard()
        this.getCollectiondata()
        this.gethistorydata()
        if (this.data.type == 1) {
    
    
            this.getmarketArticle(0)
            this.getmarketArticle(1)
            this.getmarketArticle(2)
            this.getmarketArticle(3)
            this.getmarketLoupanList()
                // this.getgetUserInfo();
            this.getgetCardIsStatus()
            this.getgetMemberCount()
            this.getsecondManageCount()

            console.log('onshow')
                // this.getgetManageUserList();
        }
        setTimeout(() => {
    
    
            wx.hideLoading()
        }, 500)

        // if (this.data.token != '') {
    
    
        //   this.setData({
    
    
        //     token: false
        //   })
        // }
    },

2.待追访列表页:

 	/**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {
    
    
        wx.stopPullDownRefresh() //刷新完成后停止下拉刷新动效
        this.getgetTagsList()
        if (this.data.isaddkehu) {
    
     // isaddkehu 参数为待追访详情页传过来的,如有值就更新页面,否则不更新列表页;
            console.log('isaddkehu')
            this.setData({
    
    
                nomore: 0,
                isLoadInterface: false,
                pagecount: 1,
                page: 1,
                kehulistarr: [],
            })
            this.getgetManageUserList()
            this.setData({
    
    
                isaddkehu: false,
            })
        }
    },

3.待追访详情页:

	// 提交待追访后,执行
	setTimeout(() => {
    
    
	  let pages = getCurrentPages() // 当前页的数据,
	  let prevPage = pages[pages.length - 2] // 上一页的数据
	  prevPage.setData({
    
    
	    isaddkehu: true, //修改上页参数值
	  })
	  // console.log(pages);
	  // wx.navigateBack({
    
    
	  //   delta: 1
	  // })
	}, 1000)

由此,在上页的 onShow 中判断这个 isaddkehu 参数值是否被修改了,就可以知道是否更新数据了。

猜你喜欢

转载自blog.csdn.net/ws19900201/article/details/111310181