<template> <view class="content"> <image @click="scan" class="img" mode="widthFix" src="../../static/img/lQDPDhs0QZY4xBXNAtDNAZWw7dBth6OpB2gCJkosywCAAA_405_720.jpg" ></image> </view> </template> <script> export default { data() { return { url: '', shopid:'', } }, onLoad() { }, methods: { scan(){ var that=this; uni.scanCode({ success: function (res) { console.log('条码类型:' + res.scanType); console.log('条码内容:' + res.result); that.url=res.result; that.shopId=that.getHashQuery('shopId') if(that.shopId){ that.gologin() }else{ uni.showToast({ title: '请扫码正确的二维码', icon: 'none', duration: 3000 }); } console.log(that.shopId) } }); }, gologin(){ uni.navigateTo({ url:'../login/login?shopId='+this.shopId }) }, getHashQuery (query) { if (this.url.indexOf(query) > -1) { let cur = this.url.slice(this.url.indexOf(query) + query.length + 1, this.url.length) if (cur.indexOf('&') > -1) { return cur.slice(0, cur.indexOf('&')) } else { return cur } } else { return false } } } } </script> <style scoped> .content{ height: 100vh; background: #000000; display: flex; align-items: flex-end; } .img{ width: 750rpx; } </style>