首页 > 其他分享 >Vue学习笔记:路由开发 Part 03

Vue学习笔记:路由开发 Part 03

时间:2023-08-07 18:04:56浏览次数:33  
标签:slot flex Vue 03 50px height ul Part tabbar

在Part 1中提到了router-link。本文档使用一个标签栏来演示其功能

在之前的例子中引入一个新的组件TabBar

tabbar.vue

<template>
    <div class="tabbar">
        <ul>
            <li><router-link to="/center" active-class="tabbar-active"> Center </router-link></li>
            <li><router-link to="/film" active-class="tabbar-active"> Film </router-link></li>
            <li><router-link to="/cinema" active-class="tabbar-active"> Cinema </router-link></li>
        </ul>
    </div>
</template>
<style scoped>
.tabbar {
    position: fixed;
    width: 100%;
    height: 50px;
    line-height: 50px;
    text-align: center;
    bottom: 0;
}

.tabbar ul {
    display: flex;
    list-style: None;
}

.tabbar ul li {
    flex: 1;
}

.tabbar-active {
    color: red;
}
</style>

在这个组件中使用router-link引入三个链接,使用active-class标注选中生效状态下的css类。

这是一种写法,还可以利用slot方式进行编写,上述可以改写为以下形式:

<template>
    <div class="tabbar">
        <!-- <ul>
            <li><router-link to="/center" active-class="tabbar-active"> Center </router-link></li>
            <li><router-link to="/film" active-class="tabbar-active"> Film </router-link></li>
            <li><router-link to="/cinema" active-class="tabbar-active"> Cinema </router-link></li>
        </ul> -->
        <ul>
            <router-link custom to="/center" v-slot="{isActive, navigate}">
            <li :class="isActive?'tabbar-active':''" @click="navigate">Center</li>
            </router-link>
            <router-link custom to="/film" v-slot="{isActive, navigate}">
            <li :class="isActive?'tabbar-active':''" @click="navigate">Film</li>
            </router-link>
            <router-link custom to="/cinema" v-slot="{isActive, navigate}">
            <li :class="isActive?'tabbar-active':''" @click="navigate">Cinema</li>
            </router-link>
        </ul>
    </div>
</template>
<style scoped>
.tabbar {
    position: fixed;
    width: 100%;
    height: 50px;
    line-height: 50px;
    text-align: center;
    bottom: 0;
}

.tabbar ul {
    display: flex;
    list-style: None;
}

.tabbar ul li {
    flex: 1;
}

.tabbar-active {
    color: red;
}
</style>

添加了custom 与v-slot。v-slot中指定了isActive 激活类 navigate跳转动作。

标签:slot,flex,Vue,03,50px,height,ul,Part,tabbar
From: https://blog.51cto.com/quietguoguo/6995971

相关文章

  • 【八股文 03】extern、static、this、inline、volatile 关键字
    0概览以下为概览,如果看到问题都能基本想到答案,则不需要看正文中详细的内容extern作用static作用修饰变量局部变量全局变量类成员变量修饰函数普通函数类成员函数this指针this指针的类型为?在常函数里this指针的类型为?inline内联函数的特点与......
  • 微信公众号授权回调 vue网址中带#号的处理
    1、改变vue模式为history,小编没有试2、通过配置nginx实现   A、替换跳转网址中的#为其他字符串,例如我的    consturl=this._getUrl("https://open.weixin.qq.com/connect/oauth2/authorize",{appid:this.appId,......
  • Windows server 2003怎么安装iisWindows server 2003安装IIS教程
    Windows2008系统服务器安装IIS之前已经分享过了,和Windows2003完全不同,今天我将详细地和你分享Windowsserver2003卸载和安装IIS的步骤方法,希望可以帮助到你~1、首先进入服务器,确定下服务器是否有安装IIS,有安装IIS,需要重装的,可以先将IIS卸载。2、卸载比安装更简单些,点击开始——......
  • MySQL问题记录Can't connect to MySQL server on 'localhost' (10061)解决方法
    登录MySQL提示Can'tconnecttoMySQLserveron'localhost'(10061)进入安装目录bin目录,执行mysqld--install,启动MySQL点击查看代码cdD:\soft\MySQL\MySQLServer5.7\binmysqld--installnetstartmysql提示启动失败最后执行mysqld--initialize--user=root--......
  • vue通过style切换背景图片,出现闪屏现象
    1.情况:通过监控swiper的index修改背景图片,出现闪屏情况 2.解决:尝试过多种方法例如v-clock,提前定义路径变量等都无法解决问题,最终使用提前定义好类名,通过修改类名动态更改类解决,在浏览器网络中可发现只请求过一次,不再是滑动时每次重新请求图片,因此不会出现闪屏现象 ......
  • vue图片压缩插件
    图片压缩插件1.安装插件npmijs-image-compressor2.引入importImageCompressorfrom'js-image-compressor'3.使用compressionImage(file){returnnewPromise((resolve,reject)=>{//eslint-disable-next-lineno-newnewImageCom......
  • 20天 hot 100 速通计划-day03
    子串239.滑动窗口最大值给你一个整数数组nums,有一个大小为k的滑动窗口从数组的最左侧移动到数组的最右侧。你只可以看到在滑动窗口内的k个数字。滑动窗口每次只向右移动一位。返回滑动窗口中的最大值。示例1:输入:nums=[1,3,-1,-3,5,3,6,7],k=3输出:[3,3,5,5,6,7......
  • node14 升级 node16 后 vue2 项目中 sass 报错问题
    起因不知道因为个什么手贱把之前的node14版本卸载了去官网重新下载安装了一下node,最近版本升级到了node16,以为应该不会有什么问题吧,结果把项目一跑,我勒个去,一堆飘红的,看控制台提示主要是这个node-sass报的错。  #卸载npmuninstallnode-sasssass-loader#重新安......
  • PEP 703作者给出的一种no-GIL的实现——python3.9的nogil版本
    PEP703的内容是什么,意义又是什么呢?可以说python的官方接受的no-GIL提议的PEP就是PEP703给出的,如果GIL帧的从python中移除那么可以说对整个python生态圈将有着跨越性发展的意义。  ====================================================  PEP703地址:https://peps.python.org......
  • vue可拖拽悬浮按钮组件
    效果预览预览地址:http://120.79.163.94/JYeontuComponents/#/JHoverBtnView关键代码实现阻止默认拖动选择事件preventEvent(){ document.getElementById('j-hover-btn').ondragstart=function(){ returnfalse; }; document.getElementById('j-hover-btn').onselectstart......