123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <template>
- <view>
- <button class="bg-blue" @click="scancode()">扫码</button>
- </view>
- </template>
- <script>
- export default {
- data() {
- return {}
- },
- onLoad() {
- // #ifdef H5
- let redirect_uri = location.href.split('#')[0]
- this.$http.get('你的接口', {
- sing_url: redirect_uri
- }).then(res => {
- this.wx_co(res.data)
- }).catch(e => {
- console.log('错误信息', e);
- });
- // #endif
- },
- methods: {
- wx_co: function(wx_co) {
- this.$wx.config({
- debug: false, // 开启调试模式
- appId: wx_co.appId, // 必填,公众号的唯一标识
- timestamp: wx_co.timestamp, // 必填,生成签名的时间戳
- nonceStr: wx_co.nonceStr, // 必填,生成签名的随机串
- signature: wx_co.signature, // 必填,签名,见附录1
- jsApiList: ['onMenuShareAppMessage', 'scanQRCode'] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
- });
- this.$wx.ready(function() { //需在用户可能点击分享按钮前就先调用
- this.$wx.checkJsApi({
- jsApiList: ['scanQRCode'], // 需要检测的JS接口列表,所有JS接口列表见附录2,
- success: function(res) {
- // 以键值对的形式返回,可用的api值true,不可用为false
- // 如:{"checkResult":{"chooseImage":true},"errMsg":"checkJsApi:ok"}
- }
- });
- });
- this.$wx.error(function(res) {
- console.log(res, 'this.$wx.error') // config信息验证失败会执行error函数
- });
- },
- scancode: function() {
- alert(1);
- this.$wx.scanQRCode({
- needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
- scanType: ["qrCode", "barCode"], // 可以指定扫二维码还是一维码,默认二者都有
- success: function(res) {
- alert(2);
- var result = res.resultStr; // 当needResult 为 1 时,扫码返回的结果
- }
- });
- }
- }
- }
- </script>
- <style lang="scss">
- </style>
|