vue+elementUI 實(shí)現(xiàn)內(nèi)容區(qū)域高度自適應(yīng)的示例
步驟很簡(jiǎn)單:
通過動(dòng)態(tài)綁定屬性給<el-main></el-main>綁定高度,而高度通過 innerHeight 獲取,減去你的頭部和底部高度,剩下的就是整個(gè)內(nèi)容區(qū)域的高度了!話不多說,上代碼
//defaultHeight是綁定的屬性<el-main :style='defaultHeight'> <router-view /></el-main> //注意:這里的defaultHeight必須是對(duì)象,不懂的可以去官網(wǎng)看下apidata() { return { defaultHeight: { height: '' } };},methods: { //定義方法,獲取高度減去頭尾 getHeight() { this.defaultHeight.height = window.innerHeight - 90 + 'px'; }},created() { //頁(yè)面創(chuàng)建時(shí)執(zhí)行一次getHeight進(jìn)行賦值,順道綁定resize事件 window.addEventListener('resize', this.getHeight); this.getHeight();}
當(dāng)然,還可以通過CSS3計(jì)算高度
<style>.el-main { height: calc(100vh - 70px);}</style>
以上就是vue+elementUI 實(shí)現(xiàn)內(nèi)容區(qū)域高度自適應(yīng)的示例的詳細(xì)內(nèi)容,更多關(guān)于vue+elementUI 實(shí)現(xiàn)內(nèi)容區(qū)域高度自適應(yīng)的資料請(qǐng)關(guān)注好吧啦網(wǎng)其它相關(guān)文章!
相關(guān)文章:
1. Warning: require(): open_basedir restriction in effect,目錄配置open_basedir報(bào)錯(cuò)問題分析2. ASP中常用的22個(gè)FSO文件操作函數(shù)整理3. php網(wǎng)絡(luò)安全中命令執(zhí)行漏洞的產(chǎn)生及本質(zhì)探究4. ASP的Global.asa文件技巧用法5. php測(cè)試程序運(yùn)行速度和頁(yè)面執(zhí)行速度的代碼6. html清除浮動(dòng)的6種方法示例7. SharePoint Server 2019新特性介紹8. ASP中if語句、select 、while循環(huán)的使用方法9. React+umi+typeScript創(chuàng)建項(xiàng)目的過程10. Vue+elementUI下拉框自定義顏色選擇器方式
