vueプロジェクトはWeChat jssdkを導入します。

1598 ワード

一、依存パッケージの導入
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)
  });
}