<view class="container"> <button bindtap='getScancode'>點擊掃碼登陸</button> <view wx:if="{{result !=''}}"> <view>掃碼的內容:{{result}}</view> </view> </view> //index.js //獲取應用實例 const app = getApp() Page({ data: { result: '' }, onLoad: function() { }, getScancode: function() { var _this = this; // 容許從相機和相冊掃碼 wx.scanCode({ success: (res) => { var result = res.result; _this.setData({ result: result, }) } }) } })
setTimeout(function () { //要延時執行的代碼 }, 1000) //延遲時間 這裏是1秒 document.write() # 取字符串長度