微信小程序扫一扫带参数跳转页面

  • A+
所属分类:Web前端
摘要

官方文档:https://developers.weixin.qq.com/miniprogram/dev/api/device/scan/wx.scanCode.htmlindex.wxml

官方文档:https://developers.weixin.qq.com/miniprogram/dev/api/device/scan/wx.scanCode.html

index.wxml

<view class="container">   <button bindtap='getScancode'>扫一扫</button> </view>

index.js

const app = getApp() Page({   data: {     result: ''   },
onLoad:
function() {
}, getScancode:
function() {
  var _this = this; wx.scanCode({ onlyFromCamera:
true,//只允许从相机扫码 success: (res) => { wx.navigateTo({ url: '../navigator/navigator?content=' + res.result }) var result = res.result; _this.setData({ result: result, }) } }) } })

要跳转的页面
navigator.wxml

<view> {{content}} </view>

navigator.js

Page({    data: {     },    onLoad: function (options) {     this.setData({       content: options.content           })    },