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-input>
<el-table :data="voucherGroupList" border>
<el-table-column prop="voucherGroupId" label="模板编码"></el-table-column>
<el-table-column prop="voucherGroupName" label="模板名称"></el-table-column>
<!-- 其他列 -->
</el-table>
</div>
</template>
<script>
import { listVoucherGroup } from '@/api/voucherGroup';
export default {
data() {
return {
searchvalue: '',
voucherGroupList: [],
queryParams: {
accountsId: '',
// 其他查询参数
},
loading: false
};
},
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;
});
},
handleQuery() {
this.queryParams.keyword = this.searchvalue;
this.getList();
},
handleTree(data, idKey, parentKey) {
// 处理树形数据的方法
}
},
mounted() {
this.getList();
}
};
</script>
<p>在上面的代码中,<code>listVoucherGroup</code>是一个接口方法,用于获取列表数据。<code>handleQuery</code>方法会在输入框输入内容并按下回车键时触发,将输入的值作为查询参数的关键字,然后调用<code>getList</code>方法重新获取列表数据。<code>mounted</code>钩子函数会在组件挂载后自动调用<code>getList</code>方法,初始化列表数据。其中的<code>handleTree</code>方法用于处理树形数据,可以根据实际情况进行实现。</p>
AI 优化版
原文地址:https://www.cveoy.top/t/topic/qwKL 著作权归作者所有。请勿转载和采集!