element-ui的图片上传怎么限制格式?

HTML代码:

    <el-upload
        style="width:300px;"
      ref="upload"
      class="upload-demo"
        :action="actionPath"
        :headers="myHeaders"
        :data="form"
        :show-file-list="true"
        :on-change="changeFileList"
        :on-success="successMethod"
        :on-remove="removeHandle"
        :on-error="errorMethod"
        :multiple="true"
        :before-upload="beforeAvatarUpload">

js代码:

methods: {
    beforeAvatarUpload(file) {
      const isJPG = file.type === 'image/jpeg';
      if (!isJPG) {
          this.$confirm('上传图片暂时只支持JPG格式', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'error' ,
            callback: action => {
              this.$refs.form.resetFields();

              this.$emit('closeEditUpload');
            }
          })
      }
      return isJPG;
    },
   }
   
 现在只能上传jpg格式,我想上传jpg和png,怎么限制???
        
阅读 10.8k
评论
    4 个回答

    accept="image/gif,image/jpeg,image/jpg,image/bmp,image/png"

    不用谢,往哪儿写就不用我说了吧