vue3 保持footer 在最底部 电脑版发表于:2025/7/22 15:33 ### flex实现的方式 在项目里边的`index.html`里边加入核心的样式: ``` <!-- 让底部保持在最下方 --> <style> #app { display: flex; flex-direction: column; justify-content: space-between; min-height: 100vh; } </style> ``` `index.html`完整的代码 ``` <!DOCTYPE html> <html lang=""> <head> <meta charset="UTF-8"> <link rel="icon" href="/favicon.ico"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Vite App</title> <!-- 让底部保持在最下方 --> <style> #app { display: flex; flex-direction: column; justify-content: space-between; min-height: 100vh; } </style> </head> <body> <div id="app"></div> <script type="module" src="/src/main.ts"></script> </body> </html> ``` **中间那块`layout.vue`可以考虑加一个`style="flex: 1"`** 就是自己实现的类似布局页的东西,当然最核心的就是上面那个这个是根据实际情况自己调整就行 ``` <script lang="ts" setup name="layout"> import Footer from './footer.vue' import Header from './header.vue' </script> <template> <Header /> <div style="flex: 1"> <RouterView /> </div> <Footer /> </template> ```