微信扫一扫有两种

1、wx.scanCode微信扫一扫,普通进入微信小程序需要微信公众平台进行配置

具体请看微信官方文档 扫普通链接二维码打开小程序 | 微信开放文档

微信扫一扫代码如下 

  <button class="codeBut" bindtap="scanBut">扫码</button>

 scanBut(){

         var that = this;

        wx.scanCode({

            success: (res) => {

                if(res.errMsg=="scanCode:ok"){

                    console.log("扫码结果");

                    this.setData({

                        code:res.result

                    })

                

                /* wx.navigateTo({

                        url: '/pages/packDetail/packDetail?packCode='+res.result+'&urlName=orderTable',

                    })*/

                    console.log(res);

                }

             

            },

            fail: (res) => {

              console.log(res);

              wx.showToast({

                title: '扫码失败',

                icon:'loading',

                duration:1500

              })

            }

        })

这个必须要配置不配置这样跳转是失败的会跳转到首页

2、微信小程序项目里中有普通二维码进入微信小程序中的某一个页面用camera组件

<view>

    <camera device-position="back" mode="scanCode" bindscancode="scan" binderror="error" style="width: 100%; height: 300px;"></camera>

</view>

 js代码

Page({

    onLoad() {},

    scan(e){

      console.log("测试一下",e);

     /*  wx.navigateTo({

        url: '/pages/packDetail/packDetail?packCode=BG202303300000000272&urlName=orderTable',

    })  */

    },

    error(){

      console.log("测试一下");

    }

  })

这样是可以进入相对应的小程序的

更多推荐