概述
- 需求為使用uni-app開發企業微信小程序。希望可以借助現成的uni-app框架,快速開發。
- 遇到的問題是uni-app引入jweixin-1.2.0.js提示異常: Reason: TypeError: Cannot read properties of undefined (reading ‘title’)。
- 本文中描述了如何解決該問題,以及jweixin-1.2.0.js引入代碼和wx.config方法調用方式。
- 本文中也描述了一種使用vconsole的方法。
解決方案
- 需要修改jweixin-1.2.0.js 文件,將下圖中的this改成window。具體解釋忘了。。。。o(╯□╰)o

- 引入后對象是jWeixin,wx對象指定的是微信小程序。
代碼
- 需要調用wx工具的頁面先引入jweixin-1.2.0.js文件。
import jWeixin from '@/static/jweixin-1.2.0.js'
jWeixin.ready(function () {console.log("wx.config: ready1");
})jWeixin.error(function (res) {console.log("wx.error", res);
})uni.request({url: "http://xxxx:9099/getSignature", header: {"Content-Type": "application/x-www-form-urlencoded;charset=utf-8"},data: {'url': encodeURI(location.href.split('#')[0])},success: (response) => {jWeixin.config({beta: true,debug: true, appId: response.data.appId, timestamp: response.data.timestamp, nonceStr: response.data.nonceStr, signature: response.data.signature,jsApiList: ['setBLEMTU','getBluetoothAdapterState','openBluetoothAdapter','onSearchBeacons','startBluetoothDevicesDiscovery','getBluetoothDevices','createBLEConnection','onBLEConnectionStateChange','closeBLEConnection','getBLEDeviceServices','getBLEDeviceCharacteristics','writeBLECharacteristicValue','readBLECharacteristicValue','notifyBLECharacteristicValueChange','notifyBLECharacteristicValueChange','notifyBLECharacteristicValueChange'] });}
});
onLoad() {const vconsole = require('@/static/vconsole.js');new vconsole();
}