import wx from 'jweixin-module'; // import Vue from 'vue'; import wxApi from '~/api/wx/index.js'; export default function (c, i) { // Vue.config.optionMergeStrategies.wxReady = function (toVal, fromVal) { // console.log( // '🚀 ~ file: jweixin.js ~ line 10 ~ toVal, fromVal', // toVal, // fromVal, // ); // // 返回合并后的值 // return []; // }; const { app } = c; i('wx', wx); app.router.afterEach(async (to, from) => { // 微信js签名注册 try { // if (to.matched[0].instances.default) { // to.matched[0].instances.default.$emit('wxReady'); // } else { // console.log(to.matched[0].components.default); // // to.matched[0].components.default.mixin({ // // mounted() { // // console.log('wxReady'); // // this.$emit('wxReady'); // // }, // // }); // } const res = await wxApi(c).getConfig(location.href); await new Promise((resolve, reject) => { wx.config({ debug: true, // 开启调试模式,调用的所有 api 的返回值会在客户端 alert 出来,若要查看传入的参数,可以在 pc 端打开,参数信息会通过 log 打出,仅在 pc 端时才会打印。 appId: res.data.appId, // 必填,公众号的唯一标识 timestamp: res.data.timestamp, // 必填,生成签名的时间戳 nonceStr: res.data.nonceStr, // 必填,生成签名的随机串 signature: res.data.signature, // 必填,签名 jsApiList: [], // 必填,需要使用的 JS 接口列表 }); wx.ready(resolve); wx.error(reject); }); } catch (error) {} }); }