1.wxss的解决办法(推荐)
@media (-webkit-min-device-pixel-ratio: 2),(min-device-pixel-ratio: 2){
.imgTest{
background: url(../images/2x.png) no-repeat;
}
}
@media (-webkit-min-device-pixel-ratio: 3),(min-device-pixel-ratio: 3){
.imgTest{
background: url(../images/3x.png) no-repeat;
}
}
2 js方法
获取设备的设备像素比,在wxml上src动态用变量引用图片
//获取设备像素比
const getPixelRatio = () => {
let pixelRatio = 0
wx.getSystemInfo({
success: function (res) {
pixelRatio = res.pixelRatio
},
fail: function () {
pixelRatio = 0
}
})
return pixelRatio
}