Menu
小程序资讯
小程序资讯
微信小程序之预览图片
时间:2016-10-13 18:36:00

 

 

选择图片时可设置图片是否是原图,图片来源。这用的也挺常见的,比如个人中心中设置头像,可以与wx.upLoadFile()API使用

主要方法:

wx.chooseImage(object)

wxml

<button type="primary" bindtap="listenerButtonChooseImage">点击我选择相册button><image src="{{source}}" mode="aspecFill" style="width: 640rpx; height: 640rpx"/>

js

Page({  data:{    // text:"这是一个页面"    source: ''  },  /**   * 选择相册或者相机 配合上传图片接口用   */  listenerButtonChooseImage: function() {      var that = this;      wx.chooseImage({          count: 1,          //original原图,compressed压缩图          sizeType: ['original'],          //album来源相册 camera相机           sourceType: ['album', 'camera'],          //成功时会回调          success: function(res) {              //重绘视图              that.setData({                  source: res.tempFilePaths              })          }      })  },


wx.previewImage(object)

这又是一个奇葩API真实搞不懂怎么用这个。先模仿下官方咋使用但是没有效果,搞懂了在补充下自己的使用

wxml

<button type="primary" bindtap="listenerButtonPreviewImage">展示图片button>

js

var app = getApp()

  Page({

    data: {

      banner:['../images/big.png', '../images/big.png', '../images/big.png'],

      modalHidden: true

    },

    tapMove:function(e){

      this.setData({ 

        num: e.detail.current+1

      })

    },

/**

  * 预览图片 

  */

   listenerButtonPreviewImage: function() {

       wx.previewImage({

           current: '../images/big.png',


            //这根本就不走

            success: function(res) {

              console.log(res);

            },

            //也根本不走

            fail: function() {

              console.log('fail')

            },

      complete:function(){

        console.log('complete')

      }

         })


       },

onLoad: function () { 

var that = this;

that.setData({

num:1,

count:that.data.banner.length

})


}

})