uni-app uni.$emit 传递数据 uni.$on 接收数据 设置data属性是失败 H5

3pmvbmvn  于 2022-11-19  发布在  uni-app
关注(0)|答案(2)|浏览(504)
uni.navigateTo({
                    url:'/pages/new....'
                    success : () => {
                        uni.$emit("news",element);
                    }
                })

第二个页面

export default {
        name: "news_details",
        data() {
            return {
                title: '',
                newData:null,
            }
        },
        onLoad(option) {
            let $this = this;
            uni.$once("news", (res) => {
                console.log("res----",res);
                $this.newData = res;
                console.log("res----",$this.newData);
            })
        },
        
        methods: {
            
        }
    }
bf1o4zei

bf1o4zei1#

Yes, I also encountered this situation. Under once, $this The newdata value exists, but not in the scope of the outlet, nor in the delay, nor in the mounted

new9mtju

new9mtju2#

不保证onLoad先于navigateTo的success执行
即:你的代码正常的前提是,调用navigateTo时,目标页面先触发onLoad,然后再触发success,

相关问题