vue项目开发

页面布局

在这里插入图片描述

实现步骤

页面分为两个个部分
1、头部
2、菜单+显示区

头部代码 top.vue
<template>
    <div style="background: rgb(245,245,245);height:70px">
        <h3 :style="title_style">{{title}}</h3>
        <img :src="img_addr" :style="img_style">
    </div>
</template>
<script>
export default {
  data () {
    return {
      title: '模组管理系统',
      title_style: {
        'display': 'inline-block',
        'text-align': 'center'
      },
      img_addr: require('../assets/images/exit.png'),
      img_style: {
        'height': '20px',
        'width': '20px',
        'position': 'absolute',
        'top': '35px',
        'right': '3%'
      }
    }
  }
}
</script>
<style>
</style>
菜单+Slider.vue
<template>
    <div>
        <div class="basic slider_style">
            <ul>
                <!-- //根据组件数量加载菜单 -->
                <li v-for="menu in menus" :key="menu.id">
                    <a @click="withdrawal(menu.vueName)">{{menu.title}}</a>
                </li>
            </ul>
        </div>
        <div class="basic main_style">
            <component :is="who"></component>
        </div>
    </div>
</template>
<script>
import update from './Update.vue'
import other from './Other.vue'
export default {
  components: {
    'update': update,
    'other': other
  },
  methods: {
    withdrawal (vueName) {
      this.who = vueName
    }
  },
  data () {
    return {
      // 设置默认加载的组件
      who: 'update',
      // 页面中所有组件
      menus: [
        {
          title: '更新',
          vueName: 'update'
        },
        {
          title: '其他',
          vueName: 'other'
        }
      ]
    }
  }
}
</script>
<style>
  .basic{
      margin: 0vh;
      padding: 0vh;
      border: 0vh;
  }
  .slider_style {
      background: rgb(150,180,125);
      float: left;
      width: 15%;
      height: 100vh;
    }
    ul,li{
        list-style:none;
        padding:0;
        margin-top:25px;
        margin-bottom: 25px;
        color: #fff;
        font-size: 16px;
    }
    .main_style{
        height:100vh;
        width:85%;
        float: left;
    }
</style>

将两个组件放到页面对应位置`

<template>
    <div id="all">
        <div id="headerBar">
            <top></top>
        </div>
        <div id="sliderBar">
            <slider></slider>
        </div>
    </div>
</template>

<script>
import slider from './Slider.vue'
import top from './Top.vue'
export default {
  name: 'Layout',
  components: {
    top,
    slider
  }
}
</script>

<style>
    #all{
        background-color:white;
        height:100%;
        width:100%;
    }
    #headerBar{
        display: inline-block;
        width: 100%;
        height: 20%;
        margin: 0%;
        padding: 0%;
        border: 0%;
    }
    #slider{
        width: 100%;
    }
</style>

通过router/index.js设置App.vue切换的组件
app.vue 主组件,所有页面都是在App.vue下进行切换

import Vue from 'vue'
import Router from 'vue-router'
import Layout from '@/components/Layout'
Vue.use(Router)

export default new Router({
  mode: 'history',
  routes: [
    {
      path: "/index.html",
      name: 'Layout',
      component: Layout
    }
  ]
})

代码结构

在这里插入图片描述

最后实现的效果
在这里插入图片描述

开发过程遇到的问题

1、 页面布局问题

第一步将页面分为上下两个部分,上部分为整个网站的标题,下部分分为菜单部分和显示区域部分,根据菜单部分,使用代码:<div class="basic main_style"><component :is="who"></component></div>调整显示部分显示的组件
使用float将

转换行内元素

2、盒子高度问题

使用height:XXX设置盒子高度,当时有XX%时盒子没有内容无法支撑盒子,但是使用XXvh,即使盒子没有内容盒子也会有固定高度

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值