wxml
<button bindtap="upimg" class='jia_img' >上传</button>
<image src="{
{tempFilePaths[0]}}"></image>
js
var app = getApp
Page({
data: {
tempFilePaths: []
},
upimg() {
var that = this
// 显示操作菜单
wx.showActionSheet({
itemList: ['拍照', '从相册中选择'],
success(res) {
console.log(res.tapIndex)
if (res.tapIndex == 0) { //0是拍照
wx.chooseImage({
count: 1,
sizeType: ['compressed'],
sourceType: ['camera'],
success: function(res) {
//res.tempFilePaths[0] 这个是图片
var tempFilePaths = res.tempFilePaths //图片
that.setData({
tempFilePaths: tempFilePaths
})
that.up()