您的位置:首页 > 移动开发 > 微信开发

微信小程序学习之路 扫一扫

2018-03-14 01:37 423 查看
[javascript] view
plain copy

//index.js  

[javascript] view
plain copy

//获取应用实例  

var app = getApp()  

Page({  

  data: {  

    show: "",  

  },  

  

  onLoad: function () {  

    console.log('onLoad')  

  },  

  click: function () {  

    var that = this;  

    var show;  

    wx.scanCode({  

      success: (res) => {  

        this.show = "--result:" + res.result + "--scanType:" + res.scanType + "--charSet:" + res.charSet + "--path:" + res.path;  

        that.setData({  

          show: this.show  

        })  

        wx.showToast({  

          title: '成功',  

          icon: 'success',  

          duration: 2000  

        })  

      },  

      fail: (res) => {  

        wx.showToast({  

          title: '失败',  

          icon: 'success',  

          duration: 2000  

        })  

      },  

      complete: (res) =>{

      }

})

}

[css] view
plain copy

.saoma{  

  height: 40px;  

  width:110px;  

  line-height: 40px;  

  margin-left: auto;  

  margin-right: auto;  

  color: #fff;  

  background-color: #999;  

  text-align: center;  

}  

.show{  

  width: 100%;  

  color: #666;  

  background-color: #fff;  

  height: auto;  

  

}  

[html] view
plain copy

<view class="container">  

  <view class="saoma" bindtap="click">点我扫一扫</view>  

  <view class="show">{{show}}</view>  

</view>  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: