+
95
-

回答

1、根目录新建一个js文件mixin.js

export const globalMixin = {
  // rpx转px
  methods: {
// rpx转px
    rpxToPx(rpx) {
      const screenWidth = uni.getSystemInfoSync().screenWidth
      return (rpx * Number.parseInt(screenWidth)) / 750
    },
	// px转rpx
	pxToRpx(px) {
	  const screenWidth = uni.getSystemInfoSync().screenWidth
	  return (750 * Number.parseInt(px)) / screenWidth
	}


  },
}

2、在main.js中引入

import { globalMixin } from "@/mixin.js"
Vue.mixin(globalMixin)

3、在其他页面view中既可使用

<view :style="'height:'+pxTorpx(100)+'rpx';"></view>

网友回复

我知道答案,我要回答