最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

elemetUi 組件--el-upload實(shí)現(xiàn)上傳Excel文件的實(shí)例

 更新時(shí)間:2017年10月27日 11:14:32   作者:未知小未來  
這篇文章主要介紹了elemetUi 組件--el-upload實(shí)現(xiàn)上傳Excel文件的實(shí)例的相關(guān)資料,希望通過本文大家能夠?qū)崿F(xiàn)這樣的功能,需要的朋友可以參考下

elemetUi 組件--el-upload實(shí)現(xiàn)上傳Excel文件的實(shí)例

【需求】實(shí)現(xiàn)上傳Excel文件,在上傳到服務(wù)器時(shí),還要附加一個(gè)參數(shù),在請(qǐng)求上傳文件接口前,先要進(jìn)行文件格式判斷。

【知識(shí)點(diǎn)】

  1、el-upload 官方文檔中,主要用到了以下屬性:

data 可選參數(shù), 上傳時(shí)附帶的額外參數(shù)
name 可選參數(shù), 上傳的文件字段名
before-upload 可選參數(shù), 上傳文件之前的鉤子,參數(shù)為上傳的文件,若返回 false 或者返回 Promise 且被 reject,則停止上傳。

  2、split進(jìn)行字符串截取

【分析】

<template>
  <div class="panel admin-panel">
    <div class="panel-head" id="add"><strong><span class="el-icon-edit"></span><span class="title">上傳數(shù)據(jù)</span></strong></div>
    <div class="body-content">
      <el-form :model="ruleForm" ref="ruleForm" label-width="100px" class="form uploadform">
        <el-form-item label="部門" prop="name">
          <el-select v-model="form.type" placeholder="請(qǐng)選擇" style="width: 135px">
            <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item>

          <el-upload
              class="upload-demo"
              ref="upload"
              action="http://10.1.20.218:8088/gnh-webadmin-platfrom/api/v1/sendSalaryBillGeinihua"
              :on-preview="handlePreview"
              :before-upload="beforeAvatarUpload"
              :on-remove="handleRemove"
              :file-list="fileList"
              :auto-upload = 'false'
              :on-success = 'handleSuccess'
              :data="form"
              name="salaryBill">
            <el-button slot="trigger" size="small" type="primary">選取文件</el-button>
            <el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload">上傳到服務(wù)器</el-button>
            <div slot="tip" class="el-upload__tip">只能上傳xls/xlsx文件</div>
          </el-upload>

        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        options: [{
          value: '1',
          label: '帥哥部'
        }, {
          value: '2',
          label: '美女部'
        }],
        fileName:'',
        fileList:[],
        ruleForm: {
//          name: '',
          isShow: '0'
        },
        form:{
          type:'1'
        },

      };
    },
    methods: {
      submitUpload() {
        this.$refs.upload.submit();
      },

      beforeAvatarUpload(file) {

        let Xls = file.name.split('.');

        if(Xls[1] === 'xls'||Xls[1] === 'xlsx'){
          return file
        }else {
          this.$message.error('上傳文件只能是 xls/xlsx 格式!')
          return false
        }

      },
      handleRemove(file, fileList) {
      },
      handlePreview(file) {
      },
      handleSuccess(res,file,fileList){

        if(res.code===20000){
          this.$message({
            message: '上傳成功!',
            type: 'success'
          });
        }else {
          this.$message({
            message: res.msg,
            type: 'error'
          });
        }

      }
    }
  }
</script>
<style scope>
  input[type="file"] {
    display: none;
  }
  .el-upload-list{
    width: 200px;
  }
  .el-select {
    width: 135px;
  }

</style>

如有疑問請(qǐng)留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!

相關(guān)文章

最新評(píng)論

罗山县| 墨江| 浠水县| 科技| 芷江| 南部县| 利津县| 湘乡市| 通海县| 长兴县| 阿鲁科尔沁旗| 瑞安市| 陇南市| 白银市| 六枝特区| 弥勒县| 陇南市| 白水县| 通江县| 阜城县| 神池县| 天镇县| 廊坊市| 大同市| 射阳县| 辽阳市| 元谋县| 南充市| 苏尼特左旗| 高要市| 延安市| 县级市| 塔城市| 遵化市| 永昌县| 宝清县| 基隆市| 同德县| 双江| 隆昌县| 山阳县|