uniapp微信小程序怎样获取宽高?获取系统信息?微信小程序 获取用户手机屏幕高度与宽度信息等
2023-09-14 09:04:08 时间
第一种方案(推荐)
"vw" = "view width"
"vh" = "view height"
使用 CSS3 引入的 vw / vh 基于宽度/高度相对于窗口大小。
/* 元素根据手机屏幕宽高占位100% */
.view {
height: 100vh;
width: 100vw;
}
第二种方案
使用微信小程序提供的 API 来获取窗口大小,具体看文档。
微信原生小程序:
onLoad: function () {
this.setData({
height: wx.getSystemInfoSync().windowHeight,
width: wx.getSystemInfoSync().windowWidth
})
}
uniapp:
uni.getSystemInfo(OBJECT) | uni-app官网https://uniapp.dcloud.io/api/system/info.html
#uni.getSystemInfo(OBJECT)
获取系统信息。
uni.getSystemInfo({
success: res => {
this.pageHeight = res.windowHeight
this.pageWidth = res.windowWidth
}
})
uni.getSystemInfoSync()
获取系统信息同步接口。同上getSystemInfo
。
const res = uni.getSystemInfoSync();
console.log(res.model);
console.log(res.pixelRatio);
console.log(res.windowWidth);
console.log(res.windowHeight);
console.log(res.language);
console.log(res.version);
console.log(res.platform);
————————————————
资料:
相关文章
- 从零开始:微信小程序新手入门宝典《一》
- H5的audio在ios系统的微信上不能自动播放的问题
- 微信小程序开发快速入手
- 微信图片生成插件,页面截图插件 html2canvas,截图失真 问题的解决方案
- 微信高级群发接口正文乱码解决方案
- 微信小程序转百度小程序代码
- 关于微信三点定位法
- 只允许微信浏览器打开自己的网页
- 微信小程序开发(十一)获取手机的完整详细信息
- 百度云和微信账号接入
- 微信第三方登录接口
- [微信] 小程序
- [FE] JS 判断当前是否在微信浏览器中的最新代码
- 美客分销商城-接力购源码系统,全开源代码可进行二次开发,微信小程序分销商城
- 使用企业微信快速注册腾讯云账号的方法
- WordPress对接微信小程序遇到的问题