效果
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;
- }
其實就是"/images/2.jpg"和"/images/3.jpg"2個字符串生成二維碼,
然后在images文件夾下放對應(yīng)路徑的2張圖片,
掃一掃二維碼重新賦值。