### 上傳多圖
> 基于weui.css
```vue
<!-- 圖片上傳 -->
<view class="img-con">
<view class="imc1">可以上傳9張圖片 {{files.length}}/9 (長按移除圖片)</view>
<view class="photo_box">
<view class="weui-uploader__bd">
<view class="weui-uploader__files" id="uploaderFiles">
<block wx:for="{{files}}" wx:key="*this">
<view class="weui-uploader__file" bindtap="previewImage" bindlongpress="deleteImage"
id="{{item}}">
<image class="weui-uploader__img" src="{{item}}" mode="aspectFill"/>
</view>
</block>
</view>
<view class="weui-uploader__input-box">
<view class="weui-uploader__input" bindtap="chooseImage"></view>
</view>
</view>
</view>
</view>
```
```javascript
/**
* 選擇圖片
* 作者:糜家智
* 時間:2021/5/10 12:09
*/
chooseImage: function (e) {
var that = this;
wx.chooseImage({
sizeType: ['original', 'compressed'], // 可以指定是原圖還是壓縮圖,默認二者都有
sourceType: ['album', 'camera'], // 可以指定來源是相冊還是相機,默認二者都有
success: function (res) {
var len = that.data.files.length + res.tempFilePaths.length
if (len >= 9){
return wx.showToast({
title: '最多上傳9張',
icon: 'none',
duration: 1200
})
}
wx.showLoading({
title: '圖片上傳中...',
})
for (var i = 0; i < res.tempFilePaths.length; i++) {
var imgUrl = res.tempFilePaths[i];
wx.uploadFile({
url: 'http://can.hrapp.com/api/action/uploadpic',
filePath: imgUrl,
name: 'file',
formData: {
user: 'test'
},
success(res) {
// 返回選定照片的本地文件路徑列表,tempFilePath可以作為img標簽的src屬性顯示圖片
console.log(res)
},
error(e) {
console.log(e)
}
})
}
wx.hideLoading()
wx.showToast({
title: '上傳成功!',
icon: 'success',
duration: 1000
})
that.setData({
files: that.data.files.concat(res.tempFilePaths)
});
}
})
},
/**預覽照片 */
previewImage: function (e) {
wx.previewImage({
current: e.currentTarget.id, // 當前顯示圖片的http鏈接
urls: this.data.files // 需要預覽的圖片http鏈接列表
})
},
/**刪除照片 */
deleteImage: function (e) {
var that = this;
var images = that.data.files;
var index = e.currentTarget.dataset.index; //獲取當前長按圖片下標
wx.showModal({
title: '系統提醒',
content: '確定要刪除此圖片嗎?',
success: function (res) {
if (res.confirm) {
images.splice(index, 1);
} else if (res.cancel) {
return false;
}
that.setData({
files: images
});
}
})
},
```
- 前端指南
- 基礎
- HTML、HTTP、web綜合問題
- css部分
- 學習指南
- 開發指南
- css指南
- JavaScript
- 視圖、文件
- canvas
- 二維碼的生成
- 64碼及圖片
- weui
- Promise
- 第三方js
- 網絡請求
- 字符串,數組,時間
- 時間類
- Css
- 布局封裝
- 媒體布局
- 九宮格圖片自適應
- 兩行顯示,且省略
- uni-app
- uniapp踩坑指南
- 表單類
- 商品規格
- 頁面操作
- H5端返回按鈕不顯示
- H5解決瀏覽器跨域問題
- uView——Waterfall 瀑布流
- uniapp中使用復制功能(復制文本到粘貼板)
- 動態導航欄的實現
- React
- React基礎
- 微信小程序
- 上傳多圖
- uni-app 微信小程序生成小程序碼二維碼帶參數
- 小程序分享圖片給好友,到朋友圈,保存到本地
- 緩存封裝
- Vue
- 深度作用選擇器deep
- 使用js實現列表無限循環滾動(橫向)
- js 無限循環垂直滾動列表
- 可視化
- AntV
- 玫瑰圖