vue 项目引入微信jssdk

1、安装jssdk

npm install weixin-js-sdk --save

2、weixin.js

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);
        //可以更新签名
      });
    });
  }
}

3、调用方法

queryJsConfig(param, callback)
{
  networklib.post('/wechat/jsconfig', param).then(obj => {
    callback(null, obj);
  }).catch(err => {
    callback(err)
  });
}
原文地址:https://www.cnblogs.com/yx-liu/p/15163231.html