<el-upload
     ref="replaceUploader"
     :file-list="replaceList"
     v-model="newChapter.title"
     class="avatar-uploader"
     action="/file/upload"
     :limit="1"
     :show-file-list="true"
     :on-success="handleReplaceAvatarSuccess"
     :on-exceed="handleExceed"
     :beforeUpload="beforeAvatarUpload">
      <el-button size="small" type="primary">点击上传</el-button>
</el-upload>

然后在methods方法中做上传文件的限制

 /**
     *上传文件限制--只能上传mp3格式的文件
     */
      beforeAvatarUpload(file) {
         var testmsg = file.name.substring(file.name.lastIndexOf('.')+1)
         const extension = testmsg === 'mp3'
         if(!extension){
           this.$message({
             message:"上传文件只能是mp3格式!",
             type:'error'
           })
         }
         return extension;
      }

 

Logo

前往低代码交流专区

更多推荐