t***@163.com
t***@163.com
  • 发布:2025-04-02 10:18
  • 更新:2025-04-21 12:00
  • 阅读:159

使用 getCurrentInstance 返回null

分类:uni-app
import { getCurrentInstance } from 'vue';  
const instance = getCurrentInstance();     // null  

const query = uni.createSelectorQuery().in(instance.proxy);  
query  
  .select("#id")  
  .boundingClientRect((data) => {  
    console.log("得到布局位置信息" + JSON.stringify(data));  
    console.log("节点离页面顶部的距离为" + data.top);  
  })  
  .exec();

现在有什么可以代替getCurrentInstance() 的方法吗

2025-04-02 10:18 负责人:无 分享
已邀请:
DCloud_UNI_yuhe

DCloud_UNI_yuhe

请说明是哪个平台,并且提供一个可以复现的项目

codon

codon

不要在异步回调中执行getCurrentInstance()

要回复问题请先登录注册