rpx2px.uvue 1.4 KB
Newer Older
DCloud-WZF's avatar
DCloud-WZF 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
<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 class="convert" type="primary" @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;
  }
H
hdx 已提交
67
</style>