更新记录
1.0.0(2026-02-07)
下载此版本
获取手机电池电量
平台兼容性
uni-app x(4.87)
| Chrome |
Safari |
Android |
iOS |
鸿蒙 |
微信小程序 |
| × |
× |
16.0 |
12 |
√ |
× |
tanheiyudoukou-getbattery
一、使用文档
import { getBatteryInfo, getBatteryInfoSync } from "@/uni_modules/tanheiyudoukou-getbattery"
getBatteryInfo({
success(res) {
console.log(res)
},
fail(err) {
console.log(err)
},
complete(res) {
console.log(res)
}
})
let info = getBatteryInfoSync()
console.log(info)
参数
Object object
| 属性 |
类型 |
必填 |
说明 |
| success |
function |
否 |
接口调用成功的回调函数 |
| fail |
function |
否 |
接口调用失败的回调函数 |
| complete |
function |
否 |
接口调用结束的回调函数(调用成功、失败都会执行) |
object.success 回调函数
| 属性 |
类型 |
说明 |
| level |
number |
设备电量,范围 1 - 100 |
| isCharging |
boolean |
是否正在充电中 |
二、适用范围
- 端类型:仅支持App端(Android/iOS/HarmonyOS)
- UniApp版本:≥ 3.0.0
- 技术栈:Vue3/TS(按需写)
三、安装方式
方式1:uni_modules 安装(推荐)
- 打开HBuilderX,进入项目根目录
- 右键「uni_modules」→「从插件市场导入」
- 搜索「插件名称」,点击安装