rpx2px.uvue 1.3 KB
Newer Older
H
hdx 已提交
1 2 3 4 5 6 7 8 9
<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>
H
hdx 已提交
10
          <text class="item-v">{{rpxValue}}rpx</text>
H
hdx 已提交
11 12 13 14 15 16 17
        </view>
        <view class="item">
          <text class="item-k">返回:</text>
          <text class="item-v">{{pxValue}}px</text>
        </view>
      </view>
      <view>
H
hdx 已提交
18
        <button class="convert" type="primary" @click="rpx2px">转换</button>
H
hdx 已提交
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
      </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);
H
hdx 已提交
38 39 40 41 42 43

        // 仅限自动化测试
        const windowInfo = uni.getWindowInfo();
        if (windowInfo.windowWidth == this.pxValue) {
          this.result = true
        }
H
hdx 已提交
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
      }
    }
  }
</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>