美文网首页
2020-02-25自动换算 2倍图 3倍图

2020-02-25自动换算 2倍图 3倍图

作者: 太阳照常升起_9c4e | 来源:发表于2020-02-25 11:07 被阅读0次
        var this_ = this;
        wx.getSystemInfo({
          success: function (res) {
            if (res.pixelRatio <= 1) {
              this_.globalData.pr = 1
            } else if (res.pixelRatio <= 2) {
              this_.globalData.pr = 2
            } else {
              this_.globalData.pr = 3
            }
          },
          fail: function () {
            this.globalData.pr = 1
          }
        })
      },
      globalData: {
        userInfo: null,
        httpurl: 'https://dkapi.stack.xin',
        pr: 1,
        user_id: null
      },
    

    utils.js

    var pr = app.globalData.pr
    const imageSrc = src => {
      return (pr == 1 || !pr) ? src : src.replace(/^(.*@)\d(x\.(png|jp?g))$/g, "$1" + pr + "$2")
    }
    module.exports = {
      imageSrc: imageSrc,
    }
    

    使用方法

    //引入 util 
    import {
      imageSrc
    } from "../../utils/util.js"
    var image = {
      search: imageSrc("https://dk-shop-img.oss-cn-beijing.aliyuncs.com/index/icon_search@1x.png"),
      wx: imageSrc("https://dk-shop-img.oss-cn-beijing.aliyuncs.com/index/icon_message@1x.png"),
    }
    

    相关文章

      网友评论

          本文标题:2020-02-25自动换算 2倍图 3倍图

          本文链接:https://www.haomeiwen.com/subject/xruzqhtx.html