let form = new FormData();
for (let i = 0; i < this.uploadFiles.length; i++) {
form.append("datafile", this.uploadFiles[i].raw);
}
this.$axios.post("/api/test", form).then((res) => {
if(res.status === 200){
let result = res.data;
if(result.code === 0){
this.$message({
message:'载入成功',
type:'success',
})
_this.xml_show = result.data;
}else{
this.$message.error('载入失败')
}
}else{
this.$message.error('服务器error')
}
});
const fs = require('fs');
const formidable = require('formidable');
exports.test = function (req, res, next) {
let form = formidable.IncomingForm();
form.parse(req, (err, field, files) => {
let filePath = files.datafile.path;
let xml = fs.readFileSync(filePath, 'utf-8');
res.send({
code:0,
data:xml,
})
})
}
以上。
|