请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

7.3 节 使用 getCurrentInstance 获取 ctx问题

老师您好:

const { ctx } = getCurrentInstance()
const { list, page } = await ctx.$api.getUserList()

ctx 获取不到globalProperties定义的 $api

图片描述

 const internalInstance = getCurrentInstance()
 const { list, page } = await internalInstance.appContext.config.globalProperties.$api.getUserList()

正在回答

插入代码

1回答

ctx换成proxy试一下

1 回复 有任何疑惑可以回复我~
  • 提问者 快乐源泉 #1
    可以了,非常感谢!
    回复 有任何疑惑可以回复我~ 2021-08-23 19:53:48
  • 提问者 快乐源泉 #2
    const { proxy } = getCurrentInstance()
    
    const { list, page } = await proxy.$api.getUserList()
    回复 有任何疑惑可以回复我~ 2021-08-23 19:54:29
  • ude 回复 提问者 快乐源泉 #3
    3q!
    回复 有任何疑惑可以回复我~ 2023-04-27 13:58:38
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号