vue导航栏制作
1,在components新建commnn目录,然后再新建nav目录,在此目录下新建nav-bottom.vue文件和nav-item.vue文件
2,nav-bottom.vue中的内容:
<template>
<div>
<div class="nav">
<slot></slot> //插槽
</div>
</div>
</template> <script>
export default {
name: "nav-bottom"
}
</script> <style scoped>
.nav {
display: flex;
position: fixed;
bottom: 0;
left: 0;
right: 0;
background-color: #7b7b7b;
height: 49px;
text-align: center;
}
</style>
3,Nav-item代码:
<template>
<div class="nav-item" :class="{isactive:isactive}">
<div @click="change">
<slot name="font-image"></slot> <--!显示字体图片-->
<slot name="font"></slot> <--!显示文字-->
</div>
</div>
</template> <script>
export default {
name: "nav-item",
props: {
path :String // 传递路径
},
computed: {
isactive () {
return this.$route.path.indexOf(this.path) !== -1
}
},
methods: {
change () {
if (this.isactive===false) {
this.$router.push(this.path)
} }
}
}
</script> <style scoped>
.nav-item {
flex: 1;
}
.isactive {
color: red;
}
</style>
4,设置导航下的每个字路由页面:
shopping 此目录下创建对应的vue文件
profile 此目录下创建对应的vue文件
homepage 此目录下创建对应的vue文件
classify 此目录下创建对应的vue文件
5,设置路由:
import Router from 'vue-router'
import Vue from 'vue' const home = () => import('../components/homepage/Home_msg')
const classify = () => import('../components/classify/Classify')
const shopping = () => import('../components/shopping/Shopping')
const profile = () => import('../components/profile/Profile') Vue.use(Router)
const routes = [
{
path: '',
redirect: '/home'
},
{
path:'/profile',
component: profile
},
{
path:'/classify',
component: classify
},
{
path:'/shopping',
component: shopping
},
{
path:'/home',
component: home
}
]
const router = new Router({
routes,
mode: 'history'
});
export default router
6,抽离组件新建navgation.vue:
<template>
<div class="aaa">
<nav-item path="home" colorstyle="blue">
<span class="iconfont" slot="font-image"></span>
<div slot="font">首页</div>
</nav-item> <nav-item path="classify" colorstyle="green">
<span class="iconfont" slot="font-image"></span>
<div slot="font">分类</div>
</nav-item> <nav-item path="shopping" colorstyle="hotpink">
<span class="iconfont" slot="font-image"></span>
<div slot="font">购物车</div>
</nav-item> <nav-item path="profile">
<span class="iconfont" slot="font-image"></span>
<div slot="font">我的</div>
</nav-item>
</div>
</template> <script>
import navItem from "./nav-item"
export default {
name: "navgative",
components: {
navItem
}
}
</script> <style scoped>
@import "../assets/images/style.css"; @font-face {font-family: 'iconfont';
src: url('../assets/images/fonts/icomoon.eot');
src: url('../assets/images/fonts/icomoon.eot?#iefix') format('embedded-opentype'),
url('../assets/images/fonts/icomoon.woff') format('woff'),
url('../assets/images/fonts/icomoon.ttf') format('truetype'),
url('../assets/images/fonts/icomoon.svg#iconfont') format('svg');
}
.iconfont{
font-family:"iconfont" !important;
font-size:16px;font-style:normal;
-webkit-font-smoothing: antialiased;
-webkit-text-stroke-width: 0.2px;
-moz-osx-font-smoothing: grayscale;
/*vertical-align: middle;*/
}
.aaa {
display: flex;
position: fixed;
bottom: 0;
left: 0;
right: 0;
}
</style>
navgation.vue
7,app.vue引入组件:
<template>
<div id="app">
<router-view></router-view>
<navBottom>
<navgative></navgative>
</navBottom>
</div>
</template> <script>
import navBottom from './components/nav-bottom'
import navgative from './components/navgative'
export default {
name: 'app',
components: {
navBottom,
navgative
}
}
</script> <style> </style>
app.vue
8,npm run serve 运行
vue导航栏制作的更多相关文章
- jquery侧边折叠导航栏制作,两行代码搞定
jquery侧边折叠导航栏制作,两行代码搞定 //CSS*{margin: 0;padding: 0} ul{list-style: none} .menu li ul{display: none} ...
- Flutter实战视频-移动电商-03.底部导航栏制作
03.底部导航栏制作 material是谷歌退出的 还有另外的一种:cupertino是IOS的风格 我们底部的导航栏,静态的widget是不合适的,这垃圾我们用到动态的widget 这重新改成动态的 ...
- Flutter实例一--底部规则导航栏制作
先来看看制作效果: 前置知识--StatefulWidget StatefulWidget具有可变状态(state)的窗口组件(widget).使用时要根据变化状态,调整State值, 能够快速初始 ...
- Vue导航栏在特定的页面不显示~
最近写vue项目遇到一些问题,我把导航栏组件放在了app.vue中,让他在每个页面都能显示了,但遇到了一个问题,在登录以及注册页面导航栏是不合理不允许存在的 解决方法: 公共模块的内容可以放在App. ...
- PHP全栈开发(八):CSS Ⅹ 导航栏制作
学习了这么久的CSS,我们现在也可以小试牛刀一下了,我们使用我们学会的CSS知识来制作一个导航栏. 我们都知道,在现代的导航栏里面,最普遍的就是使用无序列表来制作导航栏. 我们可以使用如下代码来制作一 ...
- 03-Flutter移动电商实战-底部导航栏制作
1.cupertino_IOS风格介绍 在Flutter里是有两种内置风格的: material风格: Material Design 是由 Google 推出的全新设计语言,这种设计语言是为手机.平 ...
- Flutter移动电商实战 --(3)底部导航栏制作
1.cupertino_IOS风格介绍 在Flutter里是有两种内置风格的: material风格: Material Design 是由 Google 推出的全新设计语言,这种设计语言是为手机.平 ...
- vue导航栏实时获取URL设置当前样式,刷新也存在!
很low 别喷, template代码: <div class="tab-itme"> <ul @click="clickit()"> ...
- vue 导航栏切换
<template> <footer class="menu"> <router-link to="/" class=" ...
随机推荐
- css滚动条美化
/*定义滚动条高宽及背景 高宽分别对应横竖滚动条的尺寸*/ ::-webkit-scrollbar { width: 5px; height: 5px; background-color: #F5F5 ...
- easyUI之ComboBox(下拉列表框)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <hea ...
- idea 双击选中一个变量,及高亮显示相同的变量
其实idea有这个功能,只是没有背景颜色,在这里有可能是编辑区的背景颜色和选中变量的背景颜色一样, 所有我们只需要调一下背景颜色就可以了 版本:ideaIU-2018.1.5 1. 到这里就结束啦..
- Product - 产品经理 - 转型
特别说明 本文是已读书籍的学习笔记和内容摘要,原文内容有少部分改动,并添加一些相关信息,但总体不影响原文表达. - ISBN: 9787568041591 - https://book.douban. ...
- bootstrap4 调整元素之间距离
影响元素之间的间距是可以通过style的margin或padding属性来实现,但这两个属性本意并不相同:margin影响的是本元素与相邻外界元素之间的距离,这里简称外边距:padding影响的元素本 ...
- 一些php常用函数积累
本文链接 <?php // id: ecffe70d3af54df9bad97b61918ace7d global $ct_path, $ct_log_path; $log_path = &qu ...
- python基础知识(继承)
继承的基本语法 class Class(继承那个基类如果有多个基类用逗号隔开,如果没有就继承object): """ 类的帮助信息""" ...
- python-Web-数据库-oracle
1.oracle体系结构 --------全局数据库,这里指物理磁盘上的数据库(物理结构,一个真实存在的磁盘目录),一般一台oracle服务器有1个全局数据库,文件占1G多.oracle允许一台 -- ...
- [CF544D]Destroying Roads_最短路_bfs
D. Destroying Roads 题目大意: In some country there are exactly n cities and m bidirectional roads conne ...
- PAT 甲级真题题解(121-155)
1121 Damn Single 模拟 // 1121 Damn Single #include <map> #include <vector> #include <cs ...