### 組件使用:
*****
```
<uploadFile?:visible.sync="visibleFile"?:on-success="fileSuccess"?/>
```
### 文件上傳至服務器處理
*****
`Api.xxx()`的請求頭同樣考慮添加 `responseType:'blob',//?流??形式`
```
//?導入上傳
fileSuccess(data)?{
??????const?param?=?new?FormData()?//?FormData?對象
??????param.append('file',?data.raw)?//?文件對象
??????//???param.append('uploadTitle',?name)?//?其他參數
??????Api.xxx(param).then(res?=>?{
????????this.visibleFile?=?false
????????console.log(res,?res.type)
??????})
}
```
### uploadFile組件
*****
```
<template>
??<ComDialog
????width="450px"
????:title="fileTitle"
????:visible="visible"
????@before-close="handleClose"
??>
????<template>
??????<slot?/>
??????<el-form
????????ref="fileForm"
????????:model="fileForm"
????????:rules="rules"
????????label-width="80px"
????????class="form-ruleForm"
??????>
????????<el-form-item?label="選擇文件"?prop="name">
??????????<el-input?v-model="fileForm.name"?placeholder="請選擇"?readonly?/>
??????????<el-upload
????????????ref="upload"
????????????class="upload-demo"
????????????:action="'#'"
????????????:show-file-list="false"
????????????:on-preview="handlePreview"
????????????:on-remove="handleRemove"
????????????:on-success="handleAvatarSuccess"
????????????:on-change="handleChange"
????????????:before-upload="beforeAvatarUpload"
????????????:auto-upload="false"
??????????>
????????????<el-button?slot="trigger"?type="primary">選取文件</el-button>
??????????</el-upload>
????????</el-form-item>
??????</el-form>
????</template>
????<template?slot="footer">
??????<el-button?type="primary"?@click="submitForm">確?定</el-button>
????</template>
??</ComDialog>
</template>
<script>
import?ComDialog?from?'@/components/ComDialog'
export?default?{
??name:?'UploadFile',
??components:?{?ComDialog?},
??props:?{
????fileTitle:?{
??????type:?String,
??????default:?'文件上傳'
????},
????visible:?{
??????type:?Boolean,
??????default:?false
????},
????onSuccess:?{
??????type:?Function,
??????default:?null
????}
??},
??data()?{
????return?{
??????rules:?{},
??????fileForm:?{
????????name:?''
??????}
????}
??},
??methods:?{
????handleChange(data)?{
??????this.fileForm?=?{?...data?}
????},
????handleRemove(file,?fileList)?{
??????console.log(file,?fileList)
????},
????handlePreview(file)?{
??????console.log(file)
????},
????handleClose()?{
??????this.fileForm?=?{
????????name:?''
??????}
??????this.$emit('update:visible',?false)
????},
????handleAvatarSuccess(data)?{
??????console.log(data)
????},
????beforeAvatarUpload(data)?{
??????console.log(data)
????},
????submitForm()?{
??????if?(this.onSuccess)?{
????????this.onSuccess(this.fileForm)
??????}?else?{
????????this.$emit('callback',?this.fileForm)
??????}
????}
??}
}
</script>
<style?lang="scss"?scoped>
::v-deep?.el-form-item__content?{
??display:?flex;
??.el-button?{
????margin-left:?16px;
??}
}
</style>
```
- 首頁
- 2021年
- 基礎知識
- 同源策略
- 跨域
- css
- less
- scss
- reset
- 超出文本顯示省略號
- 默認滾動條
- 清除浮動
- line-height與vertical-align
- box-sizing
- 動畫
- 布局
- JavaScript
- 設計模式
- 深淺拷貝
- 排序
- canvas
- 防抖節流
- 獲取屏幕/可視區域寬高
- 正則
- 重繪重排
- rem換算
- 手寫算法
- apply、call和bind原理與實現
- this的理解-普通函數、箭頭函數
- node
- nodejs
- express
- koa
- egg
- 基于nodeJS的全棧項目
- 小程序
- 常見問題
- ec-canvas之橫豎屏切換重繪
- 公眾號后臺基本配置
- 小程序發布協議更新
- 小程序引入iconfont字體
- Uni-app
- 環境搭建
- 項目搭建
- 數據庫
- MySQL數據庫安裝
- 數據庫圖形化界面常用命令行
- cmd命令行操作數據庫
- Redis安裝
- APP
- 控制縮放meta
- GIT
- 常用命令
- vsCode
- 常用插件
- Ajax
- axios-services
- 文章
- 如何讓代碼更加優雅
- 虛擬滾動
- 網站收藏
- 防抖節流之定時器清除問題
- 號稱破解全網會員的腳本
- 資料筆記
- 資料筆記2
- 公司面試題
- 服務器相關
- 前端自動化部署-jenkins
- nginx.conf配置
- https添加證書
- shell基本命令
- 微型ssh-deploy前端部署插件
- webpack
- 深入理解loader
- 深入理解plugin
- webpack注意事項
- vite和webpack區別
- React
- react+antd搭建
- Vue
- vue-cli
- vue.config.js
- 面板分割左右拖動
- vvmily-admin-template
- v-if與v-for那個優先級高?
- 下載excel
- 導入excel
- Echart-China-Map
- vue-xlsx(解析excel)
- 給elementUI的el-table添加骨架
- cdn引入配置
- Vue2.x之defineProperty應用
- 徹底弄懂diff算法的key作用
- 復制模板內容
- 表格操作按鈕太多
- element常用組件二次封裝
- Vue3.x
- Vue3快速上手(第一天)
- Vue3.x快速上手(第二天)
- Vue3.x快速上手(第三天)
- vue3+element-plus搭建項目
- vue3
- 腳手架
- vvmily-cli
- TS
- ts筆記
- common
- Date
- utils
- axios封裝
- 2022年
- HTML
- CSS基礎
- JavaScript 基礎
- 前端框架Vue
- 計算機網絡
- 瀏覽器相關
- 性能優化
- js手寫代碼
- 前端安全
- 前端算法
- 前端構建與編譯
- 操作系統
- Node.js
- 一些開放問題、智力題