简体中文
将rpx单位值转换成px
| Web | 微信小程序 | Android | iOS | HarmonyOS | HarmonyOS(Vapor) |
|---|---|---|---|---|---|
| 4.02 | 4.41 | 4.02 | 4.11 | 4.61 | 5.0 |
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|---|
| number | number | 是 | - | - |
| 类型 |
|---|
| number |
示例为hello uni-app x alpha分支,与最新HBuilderX Alpha版同步。与最新正式版同步的master分支示例另见
示例
<template>
<!-- #ifdef APP -->
<scroll-view class="page-scroll-view">
<!-- #endif -->
<view class="page">
<page-head :title="data.title"></page-head>
<view>
<view class="item">
<text class="item-k">输入:</text>
<text class="item-v">{{data.rpxValue}}rpx</text>
</view>
<view class="item">
<text class="item-k">返回:</text>
<text class="item-v">{{data.pxValue}}px</text>
</view>
</view>
<view>
<button id="convert" @click="rpx2px">转换</button>
</view>
</view>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
<script setup lang="uts">
type DataType = {
title: string;
rpxValue: number;
pxValue: number;
result: boolean;
}
const data = reactive({
title: 'rpx2px',
rpxValue: 750,
pxValue: 0,
result: false
} as DataType)
const rpx2px = () => {
data.pxValue = uni.rpx2px(data.rpxValue);
// 仅限自动化测试
const windowInfo = uni.getWindowInfo();
if (windowInfo.windowWidth == data.pxValue) {
data.result = true
}
}
defineExpose({
data
})
</script>
<style>
.page {
padding: 15px;
}
.item {
flex-direction: row;
}
.item-k {
width: 72px;
line-height: 2;
}
.item-v {
font-weight: bold;
line-height: 2;
}
</style>
| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|---|
| errMsg | string | 是 | - | 错误信息 |