iview组件篇之布局

本文介绍了iview框架中的24栅格布局系统,详细讲解了如何利用Row和Col创建均匀分布的列,并展示了如何实现滚动悬停效果。同时,文章还探讨了垂直居中在modal模态框中的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一.iview中24栅格布局介绍
1.1 iview24列栅格布局介绍

引入概念:
Row代表一行
Col代表一列
Card代表着卡片

<template>
  <div>
    <Row>
      <Col v-for='n in 24' span="1" :key='n'>
        <Card :title=n>
            {{ n }}列
        </Card>
      </Col>
    </Row>
  </div>
</template>
 
<script>
export default {
  name: 'app',
  data(){ 
    return {
      activeName: this.$route.path
    }
    
  },
  methods:{
  },
  watch: {
    '$route' () {
      this.activeName=this.$route.path;
      console.log(this.activeName);
    }
  }
}
</script>

<style scoped>
  body {
    background-color: #c0c0c0 !important;
  }
</style>

效果如下:
在这里插入图片描述
我们可以看到一行被平均分成了24列,这就是iview基本的24栅格布局,其中span代表着每一个列占据的24栅格的栅格数量

1.2 滚动悬停

IView中可以使用<Affix></Affix>来控制页面滚动时的悬停

<template>
  <div class="primary">
    <Row :gutter="32">
      <Col span="8">
        <Card>
            <div style="height:600px"></div>
        </Card>
      </Col>
      <Col span="16">
        <Card>
          <div style="height: 100px"></div>
        </Card>
        <Affix>
          <Card>
            <div style="height:200px"></div>
          </Card>
        </Affix> 
      </Col>
    </Row>
  </div>
</template>
 
<script>
export default {
  name: 'app',
}
</script>

<style>
  body {
    height: 5000px;
    background: #f8f8f9 !important;
  }
</style>


实现效果,我们可以看到上卡片中内容滚动完,二卡片才开始悬停
在这里插入图片描述
有时候我们布局希望滚动悬停的地方不能和导航栏覆盖,我们希望滚动悬停的位置刚好到导航栏底部

<template>
  <div class="primary">
    <div style="width:100%;height:50px;position:fixed;background-color:red;z-index:10;"></div>
    <Row :gutter="32">
      <Col span="8">
        <Card>
            <div style="height:600px"></div>
        </Card>
      </Col>
      <Col span="16">
        <Card>
          <div style="height:200px;"></div>
        </Card>
        <Affix :offset-top="50">
          <Card>
            <div style="height:200px"></div>
          </Card>
        </Affix> 
      </Col>
    </Row>
  </div>
</template>
 
<script>
export default {
  name: 'app',
}
</script>

<style>
  body {
    height: 5000px;
    background: #f8f8f9 !important;
  }
</style>

实现效果,二卡片的内容刚好到导航栏红色底部悬停
在这里插入图片描述

1.1 垂直居中效果(modal模态框)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值