uni-app 【已解决】getCurrentInstance在vue3的小程序环境无效
uni-app 【已解决】getCurrentInstance在vue3的小程序环境无效
产品分类
uniapp/小程序/微信
PC开发环境操作系统
Mac
PC开发环境操作系统版本号
M2 Max
HBuilderX类型
正式
HBuilderX版本号
4.08
第三方开发者工具版本号
1.06.2402040 darwin-arm64
基础库版本号
3.3.5
项目创建方式
HBuilderX
示例代码
<template>
<view class="">
222
</view>
</template>
<script setup>
console.log(getCurrentInstance())
</script>
操作步骤
在hx中运行到微信小程序开发工具
预期结果
getCurrentInstance可在小程序生效
实际结果
报方法不存在
bug描述
getCurrentInstance在微信小程序中无效,报方法不存在,在文档中有说明getCurrentInstance在小程序是可用的。
图片

更多关于uni-app 【已解决】getCurrentInstance在vue3的小程序环境无效的实战教程也可以访问 https://www.itying.com/category-93-b0.html
4 回复
需要引入,不建议使用
import { getCurrentInstance } from “vue”;
更多关于uni-app 【已解决】getCurrentInstance在vue3的小程序环境无效的实战教程也可以访问 https://www.itying.com/category-93-b0.html
确实如此,失误了。 以前在vue2,包括现在的vue3 app,uni-app x app中,又是不需要import就能用的。
createCanvasContext、createSelectorQuery 在子组件调用不是必须传递this吗,只能使用getCurrentInstance获取吧


