<div id='search'>
<el-upload
:multiple="false"
:show-file-list="false"
//:on-success="handleImageSuccess" //上传成功后出发
:before-upload="handleBeforeUpload"//上传前钩子函数
accept=".json"
class="image-uploader"
action="上传文件路径"
>
<div class="el-upload__text">
<el-button type="primary">点击上传</el-button>
</div>
</el-upload>
</div>
//上传前钩子函数
handleBeforeUpload(file) {
let url = null;
if(window.createObjectURL !== undefined) { // basic
url = window.createObjectURL(file);
} else if(window.URL !== undefined) { // mozilla(firefox)
url = window.URL.createObjectURL(file);
} else if(window.webkitURL !== undefined) { // webkit or chrome
url = window.webkitURL.createObjectURL(file);
}
//利用Axios读取JSON数据
this.$axios.get(url).then(res=>{
console.log(res)//读取文件内容
}).catch(err=>{
throw err
})
}
返回结果