用naive ui画个表格查询,查询条件有:文本输入框, 选择框。查询按钮有:统计(点击统计时查询数据),重置(点击重置时把查询条件的组件值清空并初始化查询))
时间: 2024-01-28 07:03:41 浏览: 442
好的,我可以为您提供一个简单的示例代码,您可以根据您的需求进行修改和调整:
```vue
<template>
<naive-table
:columns="columns"
:data="tableData"
:loading="loading"
>
<naive-table-column
prop="name"
label="名称"
/>
<naive-table-column
prop="type"
label="类型"
/>
<naive-table-column
prop="price"
label="价格"
/>
</naive-table>
<naive-form :model="queryForm" :rules="queryRules" ref="queryFormRef">
<naive-form-item label="名称" prop="name">
<naive-input v-model="queryForm.name" placeholder="请输入名称" />
</naive-form-item>
<naive-form-item label="类型" prop="type">
<naive-select v-model="queryForm.type" placeholder="请选择类型">
<naive-option label="类型1" value="type1" />
<naive-option label="类型2" value="type2" />
<naive-option label="类型3" value="type3" />
</naive-select>
</naive-form-item>
<naive-form-item>
<naive-button type="primary" @click="handleQuery">统计</naive-button>
<naive-button @click="handleReset">重置</naive-button>
</naive-form-item>
</naive-form>
</template>
<script>
export default {
data() {
return {
loading: false,
tableData: [],
queryForm: {
name: '',
type: '',
},
queryRules: {
name: [{ required: true, message: '请输入名称', trigger: 'blur' }],
type: [{ required: true, message: '请选择类型', trigger: 'change' }],
},
columns: [
{
prop: 'name',
label: '名称',
},
{
prop: 'type',
label: '类型',
},
{
prop: 'price',
label: '价格',
},
],
}
},
methods: {
handleQuery() {
this.$refs.queryFormRef.validate(valid => {
if (valid) {
// 发送查询请求,根据查询条件获取数据
this.loading = true
// your query code here
// 模拟异步请求
setTimeout(() => {
this.tableData = [
{ name: '商品1', type: 'type1', price: 100 },
{ name: '商品2', type: 'type2', price: 200 },
{ name: '商品3', type: 'type3', price: 300 },
]
this.loading = false
}, 1000)
}
})
},
handleReset() {
this.$refs.queryFormRef.resetFields()
this.tableData = []
},
},
}
</script>
```
这是一个简单的表格查询页面,包括一个表格和一个查询表单。您可以根据您的实际需求进行修改和调整。
阅读全文