1***@qq.com
1***@qq.com
  • 发布:2023-12-23 19:51
  • 更新:2024-01-05 20:52
  • 阅读:184

uniapp 使用vue3开发微信小程序,报警告导致页面跳转被跳转页面生命周期函数失效

分类:uni-app

uniapp 使用vue3开发微信小程序,报警告onLoad is called when there is no active component instance to be associated with. Lifecycle injection APIs can only be used during execution of setup()
导致页面跳转被跳转页面生命周期函数失效
被跳转页面

<template>  
    <view class="main">  

    </view>  
</template>  

<script>  
    import {onLoad} from "@dcloudio/uni-app"  
    onLoad((e) => {  
        console.log(e);  
    })   
</script>  

<style lang="scss">  

</style>
2023-12-23 19:51 负责人:DCloud_UNI_HRK 分享
已邀请:

最佳回复

DCloud_UNI_HRK

DCloud_UNI_HRK

报错已经很明显了,你的vue3语法写错了,你使用的是语法糖写法,需要在script 后面加上setup,或者像下面这样

<script>  
    import {onLoad} from '@dcloudio/uni-app';  
    export default {  
        setup() {  
            onLoad(() => {  
                console.log("app")  
            })  
        }  
    }  
</script>

要回复问题请先登录注册