设为首页收藏本站
查看: 731|回复: 3

[前端开发] Vue2 Layout布局

[复制链接]
  • TA的每日心情
    奋斗
    1 小时前
  • 签到天数: 728 天

    [LV.9]以坛为家II

    发表于 2024-3-29 12:30:00 | 显示全部楼层 |阅读模式
    1. vue create web
    复制代码


    src/layout/conpoments/index.js

    1. export { default as HeaderBar} from './headerBar.vue'
    2. export { default as Main} from './main.vue'
    复制代码


    src/layout/conpoments/headerBar.vue

    1. <template>
    2.     <div class="header-pc">
    3.         <div class="container">
    4.             <ul>
    5.                 <li :class="this.$route.path=='/'?'active':''"><a href="/">Home</a></li>
    6.                 <li :class="this.$route.path=='/store'?'active':''"><a href="/store">Merchant-side</a></li>
    7.                 <li :class="this.$route.path=='/delivery'?'active':''"><a href="/delivery">Delivery-side</a></li>
    8.                 <li :class="this.$route.path=='/about'?'active':''"><a href="/about">About US</a></li>
    9.             </ul>
    10.             <a class="app-down" href="/app">APP下载</a>
    11.         </div>
    12.     </div>
    13. </template>

    14. <script>
    15. export default{
    16.     methods:{
    17.         
    18.     },
    19.     mounted () {
    20.     console.log('---------------->mounted')
    21.     console.log(this.$route)
    22.   },
    23. }
    24. </script>

    25. <style>
    26. .header-pc {
    27.     font-size: 14px;
    28.     line-height: 20px;
    29.     overflow: hidden;
    30.     box-shadow: 0 0 10px rgba(0,0,0,.3);
    31.     background: #f3f3f3;
    32.     background-image: linear-gradient(-180deg, #fefefe, #f3f3f3);
    33. }
    34. .header-pc ul li.active a, .header-pc ul li a:hover {
    35.     color: #19a0f5;
    36. }
    37. .header-pc ul li.active a:after {
    38.     content: "";
    39.     position: absolute;
    40.     margin-left: -3px;
    41.     top: 30px;
    42.     left: 50%;
    43.     width: 6px;
    44.     height: 6px;
    45.     border-radius: 50%;
    46.     background: #19a0f5;
    47. }
    48. .header-pc .app-down {
    49.     float: right;
    50.     margin-top: 14px;
    51.     padding: 8px 27px;
    52.     text-decoration: none;
    53.     color: #fff;
    54.     background: #24a5f5;
    55.     background-image: linear-gradient(-180deg, #5dbbf5, #24a5f5);
    56.     border: 1px solid #2da6f1;
    57.     border-radius: 4px;
    58. }
    59. .container {
    60.     margin: 0 auto;
    61.     width: 1200px;
    62.     box-sizing: border-box;
    63.     height: 60px;
    64. }
    65. ul,ul li{
    66.     display: inline-block;
    67. }
    68. ul li a{
    69.     position: relative;
    70.     color: #989a9c;
    71.     margin: 20px;
    72.     display: inherit;
    73.     margin-top: 20px;
    74. }
    75. </style>
    复制代码

    src/layout/conpoments/main.vue
    1. <template>
    2.     <router-view/>
    3. </template>

    4. <script>
    5. </script>
    复制代码


    src/layout/layout.vue
    1. <template>
    2.     <div>
    3.         <HeaderBar></HeaderBar>
    4.         <Main></Main>
    5.     </div>
    6. </template>

    7. <script>
    8. import { HeaderBar,Main } from './components'
    9. export default{
    10.     components:{
    11.         HeaderBar,
    12.         Main
    13.     }

    14. }
    15. </script>
    复制代码


    src/route/index.js
    1. import Vue from 'vue'
    2. import VueRouter from 'vue-router'
    3. import Layout from '../layout/layout'
    4. import App from '../views/app'
    5. import About from '../views/about'
    6. import Store from '../views/store'
    7. import Delivery from '../views/delivery'
    8. import Home from '../views/home'
    9. Vue.use(VueRouter)

    10. const routes = [
    11.   {
    12.     path: '/',
    13.     component: Layout,
    14.     children:[
    15.       {
    16.         path: '',
    17.         name: 'index',
    18.         component: Home
    19.       },
    20.       {
    21.         path: '/app',
    22.         name: 'app',
    23.         component: App
    24.       },
    25.       {
    26.         path: '/about',
    27.         name: 'about',
    28.         component: About
    29.       },
    30.       {
    31.         path: '/store',
    32.         name: 'store',
    33.         component: Store
    34.       },
    35.       {
    36.         path: '/delivery',
    37.         name: 'delivery',
    38.         component: Delivery
    39.       }
    40.     ]
    41.   }
    42. ]

    43. const router = new VueRouter({
    44.   mode: 'history',
    45.   base: process.env.BASE_URL,
    46.   routes
    47. })

    48. export default router
    复制代码


    运行效果

    本帖子中包含更多资源

    您需要 登录 才可以下载或查看,没有帐号?注册

    x

    点评

    正好最近在学前端。  发表于 2024-4-1 08:28
  • TA的每日心情
    开心
    5 小时前
  • 签到天数: 372 天

    [LV.9]以坛为家II

    发表于 2024-3-30 09:52:55 | 显示全部楼层
    谢谢分享,已回复。
    回复 支持 反对

    使用道具 举报

    您需要登录后才可以回帖 登录 | 注册

    本版积分规则

    红盟社区--红客联盟 

    Processed in 0.058825 second(s), 23 queries.

    站点统计| 举报| Archiver| 手机版| 黑屋 |   

    备案号:冀ICP备20006029号-1 Powered by HUC © 2001-2021 Comsenz Inc.

    手机扫我进入移动触屏客户端

    关注我们可获取更多热点资讯

    Honor accompaniments. theme macfee

    快速回复 返回顶部 返回列表