美文网首页
页面图片预加载方法及微信分享配置的方法记录

页面图片预加载方法及微信分享配置的方法记录

作者: chouchou723 | 来源:发表于2019-01-24 09:44 被阅读0次

    页面图片预加载:

    preload() {
            let imgs = [{
                src: require('../assets/bg1.png')
              },
              {
                src: require('../assets/input.png')
              },
              {
                src: require('../assets/banner.png')
              },
              {
                src: require('../assets/bg3.png')
              },
              {
                src: require('../assets/hasGetted.png')
              },
              {
                src: require('../assets/getAward.png')
              },
              {
                src: require('../assets/hasPromotion.png')
              },
              {
                src: require('../assets/promotion.png')
              }
            ]
            imgs.map(item => {
              let image = new Image()
              image.src = item.src
              image.onload = () => {
                this.imgn++;
                if (this.imgn === 3) {
                  this.status = 'initial'
                }
              }
            })
          },
    

    微信分享配置:

    wechatConfig() { //create获取config
            let url = location.href.split('#')[0]
            getWx({
              url: url
            }).then((response) => {
              // this.$wechat.config(JSON.parse(response.data.data))
              //api调接口之后配置
              let data = response.data;
              console.log(data)
              wx.config({
                debug: false,
                appId: data.appId, // 必填,公众号的唯一标识
                timestamp: data.timestamp, // 必填,生成签名的时间戳
                nonceStr: data.nonceStr, // 必填,生成签名的随机串
                signature: data.signature, // 必填,微信签名
                jsApiList: [
                  'updateAppMessageShareData', 'updateTimelineShareData'
                ] // 必填,需要使用的JS接口列表
              });
              let _this = this;
              wx.ready(function() {
                //              alert(window.location.href.split('#')[0]);
                //分享到朋友/qq
                wx.updateAppMessageShareData({
                  title: '艺下送您大红包', // 分享标题
                  desc: '艺下君送您装饰画礼包', // 分享描述
                  link: window.location.href.split('#')[0], // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
                  imgUrl: require('../assets/logo.png'), // 分享图标
                  success: function(res) {
                    // 用户确认分享后执行的回调函数
                    // logUtil.printLog("分享到朋友圈成功返回的信息为:", res);
                    // _this.showMsg("分享成功!")
                  },
                  cancel: function(res) {
                    // 用户取消分享后执行的回调函数
                    // logUtil.printLog("取消分享到朋友圈返回的信息为:", res);
                  }
                });
                //分享给朋友圈 空间
                wx.updateTimelineShareData({
                  title: '艺下送您大红包', // 分享标题
                  link: window.location.href.split('#')[0], // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
                  imgUrl: require('../assets/logo.png'), // 分享图标
                  success: function(res) {
                    // 用户确认分享后执行的回调函数
                    // logUtil.printLog("分享给朋友成功返回的信息为:", res);
                  },
                  cancel: function(res) {
                    // 用户取消分享后执行的回调函数
                    // logUtil.printLog("取消分享给朋友返回的信息为:", res);
                  }
                });
              });
            }).catch(() => {
              // this.$vux.loading.hide()
            })
          },
    

    相关文章

      网友评论

          本文标题:页面图片预加载方法及微信分享配置的方法记录

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