5***@qq.com
5***@qq.com
  • 发布:2023-11-28 08:53
  • 更新:2023-11-28 14:57
  • 阅读:471

我的uni-appx项目 onBackPress方法,程序编译时报错‌error: Type mismatch: inferred type is (OnBackPressOptions)

分类:uni-app x

我的uni-appx项目 我在页面增加了onBackPress监听返回的方法,
程序编译时报错‌

‌error: Type mismatch: inferred type is (OnBackPressOptions) -> Unit but OnBackPress / = (OnBackPressOptions) -> Boolean? / was expected‌

我的代码

        //监听页面返回   
        onBackPress(Options){  
             console.log('onBackPress==',Options)  
        },  
        //监听页面加载  
        onLoad() {  
             this.init();  
             // console.log('KeyEvent==',KeyEvent)  
        },

程序报错:

08:46:43.100 [plugin:uni:app-uts] 编译失败  
08:46:43.100 ‌error: Type mismatch: inferred type is (OnBackPressOptions) -> Unit but OnBackPress /* = (OnBackPressOptions) -> Boolean? */ was expected‌

2023-11-28 08:53 负责人:无 分享
已邀请:
5***@qq.com

5***@qq.com (作者)

uni-appx项目 的onBackPress方法,应该这样用

onLoad() {  
    this.onLoadTime = Date.now()  
    console.log('onLoad', this.onLoadTime)  
  },  
  onShow() {  
    this.onShowTime = Date.now()  
    console.log('onShow', this.onShowTime)  
  },  
  onReady() {  
    this.onReadyTime = Date.now()  
    console.log('onReady', this.onReadyTime)  
  },  
  onHide() {  
    this.onHideTime = Date.now()  
    console.log('onHide', this.onHideTime)  
  },  
  onBackPress(options: OnBackPressOptions): boolean | null {  
    console.log('onBackPress', Date.now())  
    console.log('onBackPress from', options.from)  
    return null  
  },  
  onUnload() {  
    console.log('onUnload', Date.now())  
  },

要回复问题请先登录注册