1.uni-app 使用 upx 作为默认尺寸单位,可以根据屏幕宽度进行自适应。uni-app 规定屏幕基准宽度750upx。
动态绑定的 style 不支持直接使用 upx。
使用uni.upx2px(Number)转换为px后再赋值。
<template> <view> <view class="half-width" :style="{width: halfWidth}"> 半屏宽度 </view> </view> </template> <script>
export default { computed: { halfWidth() { return uni.upx2px(750 / 2) + 'px'; } } } </script>