前言:哈喽,大家好,今天给大家分享一篇文章!并提供具体代码帮助大家深入理解,彻底掌握!创作不易,如果能帮助到大家或者给大家一些灵感和启发,欢迎收藏+关注哦 💕
目录
- DeepSeek 助力 Vue3 开发:打造丝滑的表格(Table)之添加列宽调整功能,示例Table14_05可排序的固定表头表格
- 📚页面效果
- 📘组件代码
- 📚代码测试
- 📚测试代码正常跑通,附其他基本代码
- 📘编写路由 src\router\index.js
- 📘编写展示入口 src\App.vue
- 📚页面效果
- 📚展望
📚📗📕📘📖🕮💡📝🗂️✍️🛠️💻🚀🎉🏗️🌐🖼️🔗📊👉🔖⚠️🌟🔐⬇️·正文开始
⬇️·🎥😊🎓📩😺🌈🤝🤖📜📋🔍✅🧰❓📄📢📈 🙋0️⃣1️⃣2️⃣3️⃣4️⃣5️⃣6️⃣7️⃣8️⃣9️⃣🔟🆗*️⃣#️⃣
DeepSeek__Vue3_TableTable14_05_12">DeepSeek 助力 Vue3 开发:打造丝滑的表格(Table)之添加列宽调整功能,示例Table14_05可排序的固定表头表格
📚页面效果
DeepSeek 助力 Vue3 开发:打造丝滑的表格(Table)之添加列宽调整功能,示例Table14_05可排序的固定表头表格">
📘组件代码
<!-- 可排序的固定表头表格 -->
<template><div class="table-demo"><h2>5. 添加表头固定功能,可排序的固定表头表格</h2><p class="description">使用 sortable 属性和列配置实现排序功能</p><div class="table-container"><Table:data="sortedData":columns="sortableColumns"fixed-headerfixed-header-height="300px"sortable:sorted-column="sortedColumn"@update:sortedColumn="handleSortChange"border/></div></div>
</template><script setup>javascript">
import { ref, computed } from 'vue'
import Table from '@/components/Table/Table.vue'const customers = ref([{ id: 1, name: '张三', age: 28, city: '北京', level: '黄金' },{ id: 2, name: '李四', age: 35, city: '上海', level: '白银' },{ id: 3, name: '王五', age: 42, city: '广州', level: '铂金' },{ id: 4, name: '赵六', age: 31, city: '深圳', level: '黄金' },{ id: 5, name: '钱七', age: 29, city: '杭州', level: '白银' }
])const sortableColumns = ref([{ title: '姓名', dataIndex: 'name', width: '120px', sortable: true },{ title: '年龄', dataIndex: 'age', width: '80px', sortable: true },{ title: '城市', dataIndex: 'city', width: '120px' },{ title: '会员等级', dataIndex: 'level', width: '120px' }
])const sortedColumn = ref({ field: null, order: null })// 排序后的数据
const sortedData = computed(() => {const { field, order } = sortedColumn.valueif (!field || !order) return customers.valuereturn [...customers.value].sort((a, b) => {if (order === 'asc') {return a[field] > b[field] ? 1 : -1} else {return a[field] < b[field] ? 1 : -1}})
})const handleSortChange = (column) => {sortedColumn.value = column
}
</script><style scoped>
.table-demo {padding: 20px;
}.description {margin: 16px 0;color: #666;
}.table-container {border: 1px solid #ebeef5;border-radius: 4px;position: relative;height: 400px;
}:deep(.table-container) {height: 300px;
}:deep(.body-container) {padding-top: 41px; /* 为固定表头留出空间 */
}:deep(.fixed-header-container) {background: white;z-index: 10;
}/* 其他样式保持不变... */
</style>
📚代码测试
运行正常
📚测试代码正常跑通,附其他基本代码
- 添加路由
- 页面展示入口
📘编写路由 src\router\index.js
javascript">import { createRouter, createWebHistory } from 'vue-router'
import RightClickMenuView from '../views/RightClickMenuView.vue'
import RangePickerView from '../views/RangePickerView.vue'const router = createRouter({history: createWebHistory(import.meta.env.BASE_URL),routes: [{path: '/',name: 'progress',component: () => import('../views/ProgressView.vue'),},{path: '/tabs',name: 'tabs',// route level code-splitting// this generates a separate chunk (About.[hash].js) for this route// which is lazy-loaded when the route is visited.// 标签页(Tabs)component: () => import('../views/TabsView.vue'),},{path: '/accordion',name: 'accordion',// 折叠面板(Accordion)component: () =&