微信公众号前端模版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.3 KiB

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1,maximum-scale=1,minimum-scale=1" >
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
<title>微信API</title>
<script type="text/javascript">
document.write('<script type="text/javascript" src="src/utils/import-util.js?t=' + new Date().getTime() + '"><\/script>')
</script>
<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
</head>
<body>
<div id="app"
v-cloak>
<div @click="test">测试</div>
</div>
<script>
Vue.createApp({
data() {
return {
show: false
}
},
created() {
wx.config({
debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId: '', // 必填,公众号的唯一标识
timestamp: new Date().getTime(), // 必填,生成签名的时间戳
nonceStr: new Date().getTime(), // 必填,生成签名的随机串
signature: '',// 必填,签名
jsApiList: ['scanQRCode'] // 必填,需要使用的JS接口列表
})
},
methods: {
test() {
window.wx.scanQRCode({
needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
scanType: ["qrCode", "barCode"], // 可以指定扫二维码还是一维码,默认二者都有
success: function (res) {
var result = res.resultStr // 当needResult 为 1 时,扫码返回的结果
alert(res.resultStr)
},
cancel: function (res) {
console.log('取消扫码了')
}
})
}
}
}).use(VueConfig)
.use(store)
.use(VueRouter.createRouter({
history: VueRouter.createWebHashHistory(),
routes: []
}))
.mount('#app');
</script>
</body>
</html>