用vue3设计一个上半部分是多个输入框并排显示,下半部分是表格,数据多的时候可以往下拉
时间: 2024-03-05 08:48:22 浏览: 291
好的,我可以帮你回答这个问题。首先,我们可以使用Vue3的Composition API来设计这个页面。具体实现方式如下:
1.创建一个vue组件,命名为InputTable。
2.在组件中引入需要的组件和库:
```javascript
<template>
<div>
<div class="input-container">
<input v-model="input1" type="text" placeholder="输入框1">
<input v-model="input2" type="text" placeholder="输入框2">
<input v-model="input3" type="text" placeholder="输入框3">
<input v-model="input4" type="text" placeholder="输入框4">
</div>
<div class="table-container">
<table>
<thead>
<tr>
<th>列1</th>
<th>列2</th>
<th>列3</th>
</tr>
</thead>
<tbody>
<tr v-for="item in data" :key="item.id">
<td>{{ item.col1 }}</td>
<td>{{ item.col2 }}</td>
<td>{{ item.col3 }}</td>
</tr>
</tbody>
</table>
<div v-if="showLoadMore" class="load-more" @click="loadMore">加载更多</div>
</div>
</div>
</template>
<script>
import { ref, reactive } from 'vue';
import axios from 'axios';
export default {
name: 'InputTable',
setup() {
const input1 = ref('');
const input2 = ref('');
const input3 = ref('');
const input4 = ref('');
const showLoadMore = ref(true);
const data = reactive([]);
const loadData = async () => {
try {
const res = await axios.get('url');
data.value = res.data;
showLoadMore.value = false;
} catch (err) {
console.log(err);
}
};
const loadMore = () => {
loadData();
};
return {
input1,
input2,
input3,
input4,
showLoadMore,
data,
loadMore
};
}
};
</script>
<style scoped>
.input-container {
display: flex;
justify-content: space-between;
}
.table-container {
max-height: 300px;
overflow-y: auto;
}
.load-more {
text-align: center;
margin: 10px;
cursor: pointer;
}
</style>
```
3.在模板中,我们把多个输入框放在一个div中,并设置样式使其排列在一行。下面放置表格,使用v-for指令渲染数据。
4.在setup函数中,我们使用ref定义多个输入框的初始值,并使用reactive定义表格数据。我们还定义了一个showLoadMore变量,用于控制是否显示“加载更多”按钮。
5.在loadData函数中,我们使用axios请求数据,并将响应的数据存储到data变量中。如果数据加载成功,我们将showLoadMore设置为false,以此来控制是否显示“加载更多”按钮。
6.loadMore函数用于点击“加载更多”按钮时调用loadData函数加载数据。
7.最后,在组件的样式中,我们设置输入框和表格的样式,并设置表格容器的最大高度和滚动条样式。
这样,一个上半部分是多个输入框并排显示,下半部分是表格,数据多的时候可以往下拉的Vue3组件就完成了。
阅读全文
相关推荐
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![md](https://img-home.csdnimg.cn/images/20250102104920.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pptx](https://img-home.csdnimg.cn/images/20241231044947.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)