【vue3 编译ctx 无法识别】TypeError: Cannot read properties of undefined (reading ‘getUserPassword‘)

`

vue3使用const { proxy } = getCurrentInstance()获取this实例时,ctx 报 undefined

在这里插入图片描述
在这里插入图片描述
解决方案:
Vue3中,getCurrentInstance代表上下文,即当前实例。ctx相当于Vue2的this, 但是使用ctx代替this时,编译会报错。此问题的解决方案就是使用proxy替代ctx

  //   获取Composition API 上下文对象
   // const { ctx} = getCurrentInstance()
    调整为
    const {
    
     proxy } = getCurrentInstance()

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/m0_47791238/article/details/134991428