Vue實現(xiàn)固定底部組件的示例
更新時間:2021年07月29日 08:39:35 作者:劉_小_二
本文主要介紹了Vue實現(xiàn)固定底部組件的示例,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
【實現(xiàn)效果】
【實現(xiàn)方式】
<template> <div id="app"> <div class="main"> <img alt="Vue logo" src="./assets/logo.png"> <HelloWorld msg="Welcome to Your Vue.js App"/> <img alt="Vue logo" src="./assets/logo.png"> </div> <div class="footer">這是固定在底部的按鈕</div> </div> </template> <script> import HelloWorld from './components/HelloWorld.vue' export default { name: 'App', components: { HelloWorld } } </script> <style> :root{ --footer-height: 50px; } body { padding: 0; margin: 0; } #app { font-family: Avenir, Helvetica, Arial, sans-serif; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-align: center; color: #2c3e50; margin-top: 60px; } .main{ padding-bottom: var(--footer-height); overflow-y: auto; } .footer{ position: fixed; bottom: 0; width: 100%; line-height: var(--footer-height); background: #42b983; color: #fff; } </style>
【增加需求】增加一個A邏輯,當(dāng)滿足A邏輯的時候,底部按鈕就不展示,其他情況則展示。
新增一個Bool值(isShow)來判斷是否顯示底部按鈕,具體代碼如下:
<template> <div id="app"> <div class="main"> <img alt="Vue logo" src="./assets/logo.png"> <HelloWorld msg="Welcome to Your Vue.js App"/> <img alt="Vue logo" src="./assets/logo.png"> </div> <div class="footer" v-if='isShow'> <div class="footer-content">這是固定在底部的按鈕</div> </div> </div> </template> <script> import HelloWorld from './components/HelloWorld.vue' export default { name: 'App', components: { HelloWorld }, data() { return { isShow: true } }, } </script> <style> :root{ --footer-height: 50px; } body { padding: 0; margin: 0; } #app { font-family: Avenir, Helvetica, Arial, sans-serif; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-align: center; color: #2c3e50; margin-top: 60px; } .main { overflow-y: auto; } .footer { height: var(--footer-height); } .footer-content { position: fixed; bottom: 0; width: 100%; line-height: var(--footer-height); background: #42b983; color: #fff; } </style>
到此這篇關(guān)于Vue實現(xiàn)固定底部組件的示例的文章就介紹到這了,更多相關(guān)Vue 固定底部內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
您可能感興趣的文章:
相關(guān)文章
Vue實現(xiàn)模糊查詢-Mysql數(shù)據(jù)庫數(shù)據(jù)
這篇文章主要介紹了基于Vue實現(xiàn)Mysql數(shù)據(jù)庫數(shù)據(jù)模糊查詢,下面文章我們主要實現(xiàn)的是輸入框中輸入數(shù)據(jù),根據(jù)輸入的結(jié)果模糊搜索數(shù)據(jù)庫對應(yīng)內(nèi)容,實現(xiàn)模糊查詢,感興趣的小伙伴可以進入文章我們一起學(xué)習(xí)2021-12-12Vue項目如何在js文件里獲取路由參數(shù)及路由跳轉(zhuǎn)
日常業(yè)務(wù)中路由跳轉(zhuǎn)的同時傳遞參數(shù)是比較常見的,下面這篇文章主要給大家介紹了關(guān)于Vue項目如何在js文件里獲取路由參數(shù)及路由跳轉(zhuǎn)的相關(guān)資料,文中通過代碼介紹的非常詳細,需要的朋友可以參考下2024-01-01vue.js實現(xiàn)點擊后動態(tài)添加class及刪除同級class的實現(xiàn)代碼
這篇文章主要介紹了vue.js實現(xiàn)點擊后動態(tài)添加class及刪除同級class的相關(guān)資料,需要的朋友可以參考下2018-04-04