rpx2px.uvue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <template>
  2. <!-- #ifdef APP -->
  3. <scroll-view class="page-scroll-view">
  4. <!-- #endif -->
  5. <view class="page">
  6. <page-head :title="title"></page-head>
  7. <view>
  8. <view class="item">
  9. <text class="item-k">输入:</text>
  10. <text class="item-v">{{rpxValue}}rpx</text>
  11. </view>
  12. <view class="item">
  13. <text class="item-k">返回:</text>
  14. <text class="item-v">{{pxValue}}px</text>
  15. </view>
  16. </view>
  17. <view>
  18. <button id="convert" @click="rpx2px">转换</button>
  19. </view>
  20. </view>
  21. <!-- #ifdef APP -->
  22. </scroll-view>
  23. <!-- #endif -->
  24. </template>
  25. <script>
  26. export default {
  27. data() {
  28. return {
  29. title: 'rpx2px',
  30. rpxValue: 750,
  31. pxValue: 0,
  32. result: false
  33. }
  34. },
  35. methods: {
  36. rpx2px: function () {
  37. this.pxValue = uni.rpx2px(this.rpxValue);
  38. // 仅限自动化测试
  39. const windowInfo = uni.getWindowInfo();
  40. if (windowInfo.windowWidth == this.pxValue) {
  41. this.result = true
  42. }
  43. }
  44. }
  45. }
  46. </script>
  47. <style>
  48. .page {
  49. padding: 15px;
  50. }
  51. .item {
  52. flex-direction: row;
  53. }
  54. .item-k {
  55. width: 72px;
  56. line-height: 2;
  57. }
  58. .item-v {
  59. font-weight: bold;
  60. line-height: 2;
  61. }
  62. </style>