[Vue3 compilation ctx cannot be recognized] TypeError: Cannot read properties of undefined (reading ‘getUserPassword‘)

`

When vue3 uses const { proxy } = getCurrentInstance() to obtain this instance, ctx reports undefined

Insert image description here
Insert image description here
Solution:
In Vue3, getCurrentInstance represents the context, that is, the current instance. ctx is equivalent to this of Vue2, but when using ctx instead of this, the compilation will report an error. The solution to this problem is to use proxy instead of ctx

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

Insert image description here

Insert image description here
Insert image description here

Guess you like

Origin blog.csdn.net/m0_47791238/article/details/134991428
Recommended