10,612
社区成员




<download-excel class="blueBtn" :data="json_data" :fields = "json_fields" id="blueBtnDownload"
worksheet = "My Worksheet" :name="excelName" ref="blueBtnDownload"
>
<el-button type="warning" icon="el-icon-top-right" @click="bn_openExport()">批量导出 </el-button>
</download-excel>
data(){
return{
//批量导出
excelName:"表格名称"//要导出表格的名称
json_fields: { //导出Excel表格的表头设置
'name': 'name',
'age': 'age',
'sex': 'sex',
'number': 'number',
},
json_data:[],//导出的表格内容,注意都是字符串
}
}
bn_openExport(){
//给表格内容赋值
var value = this.value; //假设这是你后台获取的内容,或者是你table表格的内容,shi json格式
for(let i=0;i<test.length;i++){
this.json_data.push({"name":value[i].name,"age":value[i].age,"sex":value[i].sex,"number":value[i].number})
}
}
this.$confirm('你确定要导出吗?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(()=>{
//用户点击了确定按钮,执行
//假设这是你后台获取的内容,或者是你table表格的内容,shi json格式
var value = this.value;
for(let i=0;i<value .length;i++){
//我们把需要导出的值导出,json格式
this.json_data.push(
{"name":value[i].name,"age":value[i].age,"sex":value[i].sex,"number":value[i].number}
);
}
}).catch((err)=>{
this.$message({
message: "用户点击了取消",
type: "info",
});
});