二、步骤
1、引入微信js-sdk npm install wx-module --save
2、在调用的页面中引入import wx from 'jweixin-module'
3、页面报错找不到模板wx-open-launch-weapp时,main.js中Vue.config.ignoredElements = [ 'wx-open-launch-weapp']
4、引入微信开放标签,在main.js中配置Vue.config.ignoredElements = [‘wx-open-launch-weapp’]出现下面报错,则将配置改为Vue.config.ignoredElements = [...Vue.config.ignoredElements, 'wx-open-launch-weapp']
5、获取wx.config注册信息
let url = window.location.href.split('#')[0];
uni.request({
url: "aaaaaaaaaaa',
method: 'GET',
header: {
'content-type': 'application/x-www-form-urlencoded'
},
success: data => {
wx.config({
debug: true,
appId: "",
imestamp: "",
nonceStr: "",
signature: "",
jsApiList: [],
openTagList: [ 'wx-open-launch-weapp']
});
wx.ready(function() {
let btn = document.getElementById('launch-btn');
btn.addEventListener('launch', e => {
console.log('success');
});
btn.addEventListener('error', e => {
console.log('fail', e.detail);
});
});
}
});
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
6、view视图层调用(需注意,html和css内容均为原生写法,不能用框架组件和框架内置样式)
<wx-open-launch-weapp
id="launch-btn"
username="gh_************"
path="****"
style="width:100%">
<script type="text/wxtag-template">
<style>
.box{width: 100%; display: flex;flex-direction: column;align-items: center;justify-content:center;}
.text{width: 100%;margin-top: 8px;font-size: 12px;color: #333333;display: inline-block;text-align: center;}
</style>
<div class="box">
<img src="https://ce.xazysoft.net/saascmt/ceapplet/dx_door.png" width="36px" height="36px"/>
<span class="text">智能门禁</span>
</div>
</script>
</wx-open-launch-weapp>
5、成功界面