el-table 中 tableHeight 控制
<el-table v-loading="tableloading" :data="tabledatas" :height="tableHeight" style="width: 100%">
import { mapGetters } from 'vuex'
computed: {
...mapGetters(
['tableHeight']
)
},
- 在vuex --store / modules/ app.js 中定义
const state = {
// 被用到了navbar中
sidebar: {
opened: Cookies.get('sidebarStatus') ? !!+Cookies.get('sidebarStatus') : true,
withoutAnimation: true // 没有动画
},
// 看这里
tableHeight: window.innerHeight - 350 // 监听高度 /// 控制高度
}
const mutations = {
// 是否折叠的状态
TOGGLE_SIDEBAR: state => {
state.sidebar.opened = !state.sidebar.opened
state.sidebar.withoutAnimation = false
if (state.sidebar.opened) {
Cookies.set('sidebarStatus', 1)
} else {
Cookies.set('sidebarStatus', 0)
}
},
CLOSE_SIDEBAR: (state, withoutAnimation) => {
Cookies.set('sidebarStatus', 0)
state.sidebar.opened = false
state.sidebar.withoutAnimation = withoutAnimation
},
TOGGLE_DEVICE: (state, device) => {
state.device = device
},
// 看这里
TABLE_HEIGHT: (state, val) => { /// 控制高度
state.tableHeight = val
}
}
- 在layout下AppMain.js中 监控 window.innerHeight
mounted() {
window.addEventListener('resize', (e) => {
this.tableHeight = window.innerHeight - 350
store.commit('app/TABLE_HEIGHT', this.tableHeight)
})
}

本文详细介绍了如何在Vue项目中使用Vuex状态管理,实现el-table组件的高度自适应。通过监听窗口大小变化并计算可用高度,动态调整tableHeight属性,确保表格在不同设备和窗口尺寸下都能完美展示。

2047

被折叠的 条评论
为什么被折叠?



