人人框架中文件上传功能(单独使用)

在Vue中引用代码
template中写

<el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
 <template slot-scope="scope">
     <el-button type="text" size="small" @click="addsave(scope.row)">上传</el-button>
 </template>
</el-table-column>
	<el-dialog title="上传文件" :visible.sync="uploadoss" width="30%">
        <div style="display: flex;text-align: center;justify-content: center">
          <el-upload
                  :action="url"
                  :file-list="fileList"
                  multiple
                  :limit="limts"
                  drag
                  :before-upload="beforeUploadHandle"
                  :on-success="successHandle"
                  class="text-center">
            <i class="el-icon-upload"></i>
            <div class="el-upload__text" v-html="$t('upload.text')"></div>
            <div class="el-upload__tip" slot="tip">{{ $t('upload.tip', { 'format': 'jpg、png、gif' }) }}</div>
          </el-upload>
        </div>
      </el-dialog>

script中写
import Cookies from 'js-cookie'
这个import是重中之重,少了不行,我就是少了这个一直没成功

data(){
	retrun{
	  url: '',
      num: 0,
      fileList: [],
      limts:1,
      uploadoss:false,
      dataForm1: {
        picAddr: '',
        zcNo: '',
        prdNo: '',
        id: '',
        bomNo: '',
        name: '',
        zcItm: '',
        zcName: '',
        dep: '',
        cusNo: ''
      },
	}
}

优先加载this.init()

mounted() {
    this.init()
    // this.getmoNo()
  },
methods:{
	init (){
      this.url = `${window.SITE_CONFIG['apiURL']}/sys/oss/upload?token=${Cookies.get('token')}`
      this.num = 0
      this.fileList = []
    },
    addsave(e){
      this.dataForm1=e
      this.uploadoss=true
    },
    //上传之前
    beforeUploadHandle (file) {
      /*if (file.type !== 'image/jpg' && file.type !== 'image/jpeg' && file.type !== 'image/png' && file.type !== 'image/gif') {
        this.$message.error(this.$t('upload.tip', { 'format': 'jpg、png、gif' }))
        return false
      }*/
      this.num++
    },
    // 上传成功
    successHandle (res, file, fileList) {
      if (res.code !== 0) {
        return this.$message.error(res.msg)
      }
      this.fileList = fileList
      this.num--
      if (this.num === 0) {
        this.$message({
          message: this.$t('prompt.success'),
          type: 'success',
          duration: 500,
          onClose: () => {
              this.uploadoss = false
              this.$emit('refreshDataList')
          }
        })
        this.dataForm1.picAddr = res.data.src
        console.log(this.dataForm1)
        this.saveList()
      }
    },
    saveList(){
      this.$http.post('/demo/mesdrawing/savadrawing',this.dataForm1)
              .then(({ data: res }) => {
                if(res.code!==0){
                  return this.$message.error("错误")
                }
                this.$message({
                  message: "操作成功",
                  type: 'success',
                  duration: 500,
                  onClose: () => {
                    this.$emit('refreshDataLists')
                  }
                })
              }).catch((error) => {
        console.log(error)
      });
    },
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值