Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.1k views
in Technique[技术] by (71.8m points)

关于uni app popup 弹出层的问题

在小程序的一个页面中, 引入了一个popup 弹出层, 通过 this.$refs.popup.open() 让弹出层触发打开, 在这个弹出层打开时, 他首先触发了什么生命周期? (因为在弹出层里有一些选项操作,希望在每次打开时,让已选中的操作都置为空)这样需要怎么操作?求指点


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

uni app 是基于 vue 的,所以弹出层大概率也是数据驱动的,盲猜弹出之前是 beforeUpdate,但是 beforeUpdate 触发条件过多,需要费点事来辨别是不是在 popup
一个万能的、不用探究其原理的写法就是覆盖它的 open 方法:

const originOpen = this.$refs.popup.open;
this.$refs.popup.open = function(...args){
    // 在这里设置已选项
    
    return originOpen.bind(this)(...args);
};

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

63 comments

56.5k users

...