4***@qq.com
4***@qq.com
  • 发布:2022-01-16 15:24
  • 更新:2023-05-20 16:20
  • 阅读:1125

uniapp vue3 getCurrentPages如何获取上一页方法

分类:uni-app

vue2 是 beforePage.$vm.init()

vue3报错 TypeError: beforePage.$vm.init is not a function

2022-01-16 15:24 负责人:无 分享
已邀请:
DCloud_UNI_LXH

DCloud_UNI_LXH

你是想调用 $vm 上的方法吗?你暴露这个方法了吗?看下你是怎么写的。如果 setup 中可能拿不到,可以换为 options 的形式书写

  • 店小二丶

    如果是setup 有好的方式么? 我现在的问题是我再详情也操作成功后想自动返回上一个,并刷新数据,目前只能靠uni.$emit 实现感觉不是很好,想问一下有没有一种更好的实现方式

    2023-04-04 10:25

  • DCloud_UNI_LXH

    回复 店小二丶: EventChannel

    2023-04-04 11:18

  • 店小二丶

    回复 DCloud_UNI_LXH: 但是在setup 中的 @dcloudio/uni-app 似乎没有提供 getOpenerEventChannel 这个方法,就没有办法像

    const eventChannel = this.getOpenerEventChannel()

    eventChannel.emit('acceptDataFromOpenedPage', {data: 'test'});

    eventChannel.emit('someEvent', {data: 'test'});

    这样使用

    2023-04-04 11:23

  • DCloud_UNI_LXH

    回复 店小二丶:


    import { getCurrentInstance } from 'vue'  
    // ...
    getCurrentInstance().proxy.getOpenerEventChannel()

    2023-04-04 15:52

c***@163.com

c***@163.com - qqq

我也碰到了这个问题,请问您这边最后解决了吗? 我已经搜好几天了

BeardYound

BeardYound

确实出了这个问题,我以前写修改上一页数据是这样写正常,现在这样写就会报错 后来我换了一种写法

A页面使用 uni.$on监听

B页面使用 uni.$emit传递修改的数据(A页面实时监听)

A页面onUnload调用uni.$off注销监听(一定要加,防止监听值相同)

要回复问题请先登录注册