vuejs 项目引入微信jssdk


一、导入依赖包
npm i -S weixin-js-sdk

二、前端页面使用

import wx from 'weixin-js-sdk'

export default {
  created() {
    let param = {
      debug: true,
      url: 'http://localhost:8081/productgroups',
      jsApiList: [
        'chooseWXPay',
        'checkJsApi'
      ]
    };
    wechatlib.queryJsConfig(param, (err, obj) => {
      if (err) {
        return this.$toast(err);
      }

      console.log('jsconfig ', obj);

      wx.config(obj);

      wx.ready(() => {
        console.log('wx.ready');
      });

      wx.error(function (res) {

        console.log('wx err', res);

        //可以更新签名
      });
    });
  }
}

三、wechatlib中获取jsconfig的方法

queryJsConfig(param, callback)
{
  networklib.post('/wechat/jsconfig', param).then(obj => {

    callback(null, obj);
  }).catch(err => {
    callback(err)
  });
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM