根据页面动态自适应宽高(window.removeEventListener("resize", 方法名);)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | <template> <el-table :height= "tableHeight" :data= "tableData" > <el-table-column header-align= "center" label= "序号" align= "center" width= "50px" > <template slot-scope= "scope" > <span>{{scope.$index+(pageIndex - 1) * pageSize + 1}}</span> </template> </el-table-column> ...其他代码 </el-table> </template> <script> export default { data(){ return { windowWidth: "" , windowHeight: "" ,<br> iptWidth: "" ,<br> pageIndex: 1,<br> pageSize: 10, } }, mounted(){ // 添加监听事件onResize start 缺一不可 this .onResize() window.addEventListener( 'resize' , this .onResize); }, methods: { // 页面缩放时重置高度 onResize() { let that = this ; that.windowWidth = document.documentElement.clientWidth; //获取屏幕宽度 that.windowHeight = document.documentElement.clientHeight; //获取屏幕高度 // console.log('屏幕高1=', that.windowHeight); if (that.windowWidth >= 1366 && that.windowWidth <= 1680) that.iptWidth = 200 if (that.windowWidth >= 1680 && that.windowWidth <= 1920) that.iptWidth = 280 this .$nextTick(() => { that.tableHeight = that.windowHeight - 136 }) }, } } </script> |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 上周热点回顾(3.3-3.9)
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」