相册选择图片选择不上

wxml中

html
<view class="container">
  <view class='img_body'>
    <view class='img_list'>
      <view class='img_li' wx:for="{{imglist}}" wx:key="index">
        <image src="{{imglist}}"></image>
        <video src=""></video>
      </view>
      <view class='addimg' bindtap='img_w_show'>
        <image src='../image/微信图片_20220108200638.jpg'></image>
      </view>
    </view>
  </view>
  </view>
javascript
 data: {
    imglist:''
    },

 img_w_show(){
        wx.chooseMedia({
         mediaType:['image','video'],
          count: 9, // 默认9
          sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
          sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
          success:res=> {
            // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
           this.setData({
               imglist:res.tempFiles.tempFilePath
           })
    
          }
      })
    },

img

点击选择图片以后 ,选择不上图片 为啥啊

在wx.chooseImage内使用this.setState会出错,需要在外面保存一份this, const _this = this,然后在success回调内 通过 _this.setState

img_w_show(){
        const _this = this
        wx.chooseMedia({
         mediaType:['image','video'],
          count: 9, // 默认9
          sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
          sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
          success:res=> {
            // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
           _this .setData({
               imglist:res.tempFiles.tempFilePath
           })
    
          }
      })
    },

你这个是多张的,你打印下rea,看数据格式,imgList是要数组


<image src="{{item}}"></image>