Vue elementUI Upload只支持上传音频格式的文件
<el-uploadref="replaceUploader":file-list="replaceList"v-model="newChapter.title"class="avatar-uploader"action="/file/upload":limit="1":show-file-list="tr...
·
<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;
}
更多推荐
已为社区贡献4条内容
所有评论(0)