用getCurrentPages来设置上一个页面的date时,wxml无法获取date?

小程序 文章 2021-01-31 01:01 520 0 全屏看文

AI助手支持GPT4.0

用getCurrentPages来设置上一个页面的date时,wxml无法获取date?When using getCurrentPages to set the date of the previous page, wxml cannot get the date?

用getCurrentPages来设置上一个页面的date时,wxml无法获取date?

比如页面A中的data有个值arr:[], 页面A是navigator到页面B,

页面B中:

let pages =  getCurrentPages()let prevPage = pages[pages.length-2]prevPage.data.arr.push('bbb')


页面B没有setData也能直接更新A页面的AppData,但wxml获取不到arr数据的,是BUG还是小程序设计的逻辑就是如此?

For example, data in page a has a value arr: [], page a is navigator to page B, page B: let pages = getcurrentpages() let prevpage = pages[ pages.length -2] prevPage.data.arr . push ('bbb ') page B can directly update the appdata of page a without SetData, but wxml can't get the ARR data. Is that bug or the logic of small program design?

回答:

布之道:设计就是如此,如果你要让视图层更新,就必须用setData来赋值
Mr.Zhao:

别说getCurrentPages了,就是在当前页面不setData,wxml也不会更新

小黎:这个就是为上个页面赋值,上个页面也可以获取到
🙈:所以就是上个页面还要在onShow的时候setData一下是吧

-EOF-

AI助手支持GPT4.0