
简体中文
将rpx单位值转换成px
Web | 微信小程序 | Android | iOS | HarmonyOS |
---|---|---|---|---|
4.02 | 4.41 | 4.02 | 4.11 | 4.61 |
名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
---|---|---|---|---|---|
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="title"></page-head>
<view>
<view class="item">
<text class="item-k">输入:</text>
<text class="item-v">{{rpxValue}}rpx</text>
</view>
<view class="item">
<text class="item-k">返回:</text>
<text class="item-v">{{pxValue}}px</text>
</view>
</view>
<view>
<button id="convert" @click="rpx2px">转换</button>
</view>
</view>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
<script>
export default {
data() {
return {
title: 'rpx2px',
rpxValue: 750,
pxValue: 0,
result: false
}
},
methods: {
rpx2px: function () {
this.pxValue = uni.rpx2px(this.rpxValue);
// 仅限自动化测试
const windowInfo = uni.getWindowInfo();
if (windowInfo.windowWidth == this.pxValue) {
this.result = true
}
}
}
}
</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 | 是 | - | 错误信息 |