import getBatteryInfo from "@/uni_modules/uts-getbatteryinfo";
export default {
data() {
return {
level: '获取中……',
}
},
onLoad() {
setInterval(() => {
this.getBat();
}, 10000);
},
onShow() {
this.getBat();
},
methods: {
getBat() {
getBatteryInfo({
success: (res) => {
this.level = res.level + '%' + (res.isCharging ? '-充电中' : '');
},
fail: () => {
this.level = '获取失败';
}
});
}
}
}
- 发布:2022-11-15 09:34
- 更新:2023-02-01 13:58
- 阅读:893
产品分类: uniapp/App
PC开发环境操作系统: Mac
PC开发环境操作系统版本号: macOS Big Sur 11.7.1
HBuilderX类型: Alpha
HBuilderX版本号: 3.6.9
手机系统: Android
手机系统版本号: Android 11
手机厂商: 小米
手机机型: Mi 10 Ultra
页面类型: nvue
vue版本: vue2
打包方式: 云端
项目创建方式: HBuilderX
操作步骤:
预期结果:
正常获取电量信息
正常获取电量信息
实际结果:
文件查找失败:'@/uni_modules/uts-getbatteryinfo'
reportJSException >>>> exception function:createInstanceContext, exception:white screen cause create instanceContext failed,check js stack ->Uncaught Error: Cannot find module '../../uni_modules/uts-getbatteryinfo'
at webpackMissingModule (<anonymous>:11:113)
at eval (<anonymous>:11:224)
at (pages/index/index.js.nvue:274:1)
at webpack_require (pages/index/index.js.nvue:21:30)
at eval (<anonymous>:2:551)
at (pages/index/index.js.nvue:263:1)
at webpack_require (pages/index/index.js.nvue:21:30)
at eval (<anonymous>:3:105)
at (pages/index/index.js.nvue:183:1)
at __webpack_require__ (pages/index/index.js.nvue:21:30)
文件查找失败:'@/uni_modules/uts-getbatteryinfo'
reportJSException >>>> exception function:createInstanceContext, exception:white screen cause create instanceContext failed,check js stack ->Uncaught Error: Cannot find module '../../uni_modules/uts-getbatteryinfo'
at webpackMissingModule (<anonymous>:11:113)
at eval (<anonymous>:11:224)
at (pages/index/index.js.nvue:274:1)
at webpack_require (pages/index/index.js.nvue:21:30)
at eval (<anonymous>:2:551)
at (pages/index/index.js.nvue:263:1)
at webpack_require (pages/index/index.js.nvue:21:30)
at eval (<anonymous>:3:105)
at (pages/index/index.js.nvue:183:1)
at __webpack_require__ (pages/index/index.js.nvue:21:30)
1 参考一下hello uts的代码用法, 电量插件需要手动导出引用,默认没有挂载到uni.xxx 上
import getBatteryInfo from "@/uni_modules/uni-getbatteryinfo";
getBatteryInfo({
success(res) {
uni.showToast({
title: "当前电量:" + res.level + '%',
icon: 'none'
});
}
})
2 如果要使用 uni.xxx 需要下载uni ext api 版本 https://ext.dcloud.net.cn/plugin?id=9295
另: UTS 开发交流群: 527828934
深沁 (作者)
感谢
2022-11-18 11:14