效果
js
let app = getApp();Page({ data: { img: "/images/1.jpg" }, onLoad() { }, scan() { wx.scanCode({ success: (res) => { console.log("掃碼結(jié)果"); console.log(res); this.setData({ img: res.result }) }, fail: (res) => { console.log(res); } }) }})
html
<view class="view"> <image class="cover-9" src="{{img}}" bindtap="img"></image> <button type="primary" bindtap="scan" id="scan">掃一掃</button></view>
css
page{ height: 100%;}.view{ width: 100%; height: 100%;}.cover-9{ width: 688rpx; height: 80%; margin: 0 30rpx; border:2rpx solid; border-radius:5px; }button{ margin: 0 10rpx; width: 100%;}#scan{ width: 730rpx;}
其實(shí)就是"/images/2.jpg"和"/images/3.jpg"2個(gè)字符串生成二維碼,
然后在images文件夾下放對(duì)應(yīng)路徑的2張圖片,
掃一掃二維碼重新賦值。
參考地址:
https://mp.weixin.qq.com/debug/wxadoc/dev/api/scancode.html
以上所述是小編給大家介紹的微信小程序-掃一掃wx.scanCode() 掃碼大變身詳解整合,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)武林網(wǎng)網(wǎng)站的支持!
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注