在vue中将xml文件解析后,用el-tree和el-table来在前端显示其数据
在这个基础上怎么能在前端上对数据进行修改后将修改后的数据保存到xml文件中
const fs = require('fs');
const json2xml = require('js2xmlparser').parse;
// 将JSON转换为XML
const xml = json2xml('data', JSON.parse(json));
// 保存XML到文件
fs.writeFileSync('data.xml', xml, 'utf-8');
<template>
<div class="app-container">
<el-table
:data="tableData"
style="width: 100%"
:header-cell-style="{
background: '#3d80f2',
color: '#fff',
fontSize: '14px',
height: '40px',
}"
>
<el-table-column
prop="numbering"
label="编号"
align="center"
></el-table-column>
<el-table-column prop="title" label="标题" align="center">
<template slot-scope="scope">
<el-input
v-model="scope.row.title"
placeholder="请输入"
></el-input>
</template>
</el-table-column>
<el-table-column prop="type" label="类型" align="center">
<template slot-scope="scope">
<el-select
v-model="scope.row.type"
placeholder="请选择"
clearable
>
<el-option
v-for="item in options"
:key="item.id"
:label="item.label"
:value="item.id"
></el-option>
</el-select>
</template>
</el-table-column>
<el-table-column prop="status" label="状态" align="center">
<template slot-scope="scope">
<el-switch v-model="scope.row.status"></el-switch>
</template>
</el-table-column>
<el-table-column label="操作">
<template slot-scope="scope">
<el-button type="text" @click="addClick">新增</el-button>
<el-button
type="text"
style="color:red;"
@click="handleDelete(scope.$index, scope.row)"
>删除</el-button
>
</template>
</el-table-column>
</el-table>
</div>
</template>
<script>
export default {
data () {
return {
tableData: [
{
numbering: "编号-1",
title: "",
type:null,
status:true,
}
],
options:[
{
id:1,
label:'类型1'
},{
id:2,
label:'类型2'
},{
id:3,
label:'类型3'
}
]
}
},
methods: {
//新增方法
addClick () {
this.valNumer = this.valNumer + 1;
var list = {
numbering: "编号" + `-${this.tableData.length + 1}`,
title: this.title,
type:this.type,
status:this.status
};
this.tableData.push(list);
},
//删除新增的某行数据
handleDelete (index, row) {
this.tableData.splice(index, 1);
for (var i = index; i < this.tableData.length; i++) {//从某一行删除了编号,删除的编号后面的编号数据要依次减一,所以遍历删除编号后面的数据
this.tableData[i].numbering = "编号" + `-${Number(this.tableData[i].numbering.split("-")[1]) - 1}`;
}
}
}
};
</script>
<style lang="scss" scoped>
.dialogDiv {
height: 300px;
overflow: auto;
}
</style>