Vue.js 实现根据接口获取列表数据并实现查询功能
<template>
<div>
<el-input
v-model="searchvalue"
placeholder="输入抽样模板编码或名称"
clearable
size="small"
@keyup.native.enter="handleQuery"
class="search-input"
style="width: 200px; margin-right: 10px"
/>
<el-table :data="voucherGroupList">
<el-table-column prop="voucherGroupId" label="Voucher Group ID"></el-table-column>
<el-table-column prop="voucherGroupName" label="Voucher Group Name"></el-table-column>
<!-- 其他列 -->
</el-table>
</div>
</template>
<script>
import { listVoucherGroup } from 'your-api-module'; // 导入listVoucherGroup接口
export default {
data() {
return {
loading: false,
queryParams: {
accountsId: '',
},
voucherGroupList: [],
searchvalue: '',
};
},
mounted() {
this.getList();
},
methods: {
getList() {
this.loading = true;
this.queryParams.accountsId = this.accountsId;
listVoucherGroup(this.queryParams)
.then((response) => {
console.log(response, 'response');
this.voucherGroupList = this.handleTree(
response.data,
'voucherGroupId',
'parentId'
);
this.loading = false;
})
.catch((error) => {
console.log(error);
this.loading = false;
});
},
handleQuery() {
axios
.get('/api/voucher-groups?query=' + this.searchvalue)
.then((response) => {
this.voucherGroupList = this.handleTree(
response.data,
'voucherGroupId',
'parentId'
);
})
.catch((error) => {
console.log(error);
});
},
handleTree(data, idKey, parentKey) {
// 处理树结构数据的方法
},
},
};
</script>
AI 优化版
原文地址:https://www.cveoy.top/t/topic/qwLt 著作权归作者所有。请勿转载和采集!