网站首页 > 博客文章 正文
最近一直在学习Nuxt开发,由于 Nuxt.js 是基于 Vue.js 的服务端渲染应用框架,只要你熟悉vue,基本能很快上手了。
Nuxt.js 基于 Vue.js 的通用应用框架,star高达29.6K+。弥补了Vue不利于SEO的缺陷。
# 文档地址
https://zh.nuxtjs.org/
# 仓库地址
https://github.com/nuxt/nuxt.js
通过如下几步即可快速构建nuxt项目。
# 创建项目
$ npx create-nuxt-app <project-name>
# 本地运行
npm run dev
# 构建
npm run build
下面就直接进入今天的主题,Nuxt.js中创建自定义顶部导航栏和底部tabbar。
首先,在components目录下新建 headerBar.vue 和 tabbar.vue 页面。
在plugins目录新建components.js组件。
在nuxt.config.js中配置插件即可。
1、自定义导航栏HeaderBar
<!-- 顶部导航headerBar.vue -->
<template>
<div class="header-bar" :class="{'fixed': fixed, 'transparent fixed': transparent}">
<div class="header-bar__wrap flexbox flex-alignc" :style="{'background': bgcolor, 'color': color}">
<!-- >>返回 -->
<div class="action hdbar-action__left isback" v-if="back && back!='false'" @click="$router.go(-1)">
<slot name="backIco" /><slot name="backText" />
</div>
<!-- >>标题 -->
<div class="hdbar-title" :class="{'center': center}">
<slot name="title" />
</div>
<!-- >>搜索框 -->
<div class="action hdbar-action__search">
<slot name="search" />
</div>
<!-- >>右侧 -->
<div class="action hdbar-action__right">
<slot name="right" />
</div>
</div>
</div>
</template>
<script>
export default {
props: {
// 是否返回
back: { type: [Boolean, String], default: true },
// 标题
title: { type: String, default: '' },
// 标题颜色
color: { type: String, default: '#fff' },
// 背景颜色
bgcolor: { type: String, default: '#22d59c' },
// 标题是否居中
center: { type: [Boolean, String], default: false },
// 搜索框
search: { type: [Boolean, String], default: false },
// 是否固定
fixed: { type: [Boolean, String], default: false },
// 背景透明
transparent: { type: [Boolean, String], default: false },
},
data() {
return {}
},
methods: {},
}
</script>
支持自定义背景(透明背景)、颜色、左侧图标、标题、搜索框,右侧按钮支持图标/文字/图片。
<header-bar :back="true" :bgcolor="bgcolor" color="#ff0" center transparent>
<template #backIco><i class="iconfont icon-close"></i></template>
<!--标题-->
<div slot="title">
<img src="~/assets/img/logo.png" height="16" /> <em>Nuxt</em>
</div>
<!--右侧按钮-->
<div slot="right"><i class="iconfont icon-search" @click="$toast('搜索~~~')"></i></div>
<div slot="right"><i class="iconfont icon-choose"></i></div>
<div slot="right"><van-button type="primary" @click="saveData">保存</van-button></div>
</header-bar>
<header-bar :back="true" bgcolor="#29a1f7" color="#90fff4">
<div slot="backIco"><i class="iconfont icon-arrL"></i></div>
<div slot="title">
<img src="~/assets/img/logo.png" height="16" /> <em>通讯录</em>
</div>
<div slot="right" class="ml-20"><i class="iconfont icon-search"></i></div>
</header-bar>
<header-bar :back="true" bgcolor="#ffb612" color="#ff0" center>
<div slot="backIco"><i class="iconfont icon-back"></i></div>
<div slot="title">理财通</div>
<div slot="right" class="ml-20"><i class="iconfont icon-choose"></i></div>
</header-bar>
2、自定义底部Tabbar
<!-- 底部TabBar.vue -->
<template>
<div class="tab-bar" :class="{'fixed': fixed}">
<div class="tab-bar__wrap flexbox flex-alignc" :style="{'background': bgcolor}">
<div v-for="(item,index) in tabs" :key="index" class="navigator" :class="currentTabIndex == index ? 'on' : ''" @click="switchTabs(index, item)">
<div class="ico" :class="{'dock': item.dock}">
<i v-if="item.dock" class="dock-bg" :style="{'background': item.dockBg ? item.dockBg : activeColor}"></i>
<i v-if="item.icon" class="iconfont" :class="item.icon" :style="{'color': (currentTabIndex == index && !item.dock ? activeColor : color), 'font-size': item.iconSize}"></i>
<img v-if="item.iconImg" class="iconimg" :src="currentTabIndex == index && !item.dock ? item.selectedIconImg : item.iconImg" :style="{'font-size': item.iconSize}" />
<em v-if="item.badge" class="nuxt__badge">{{item.badge}}</em>
<em v-if="item.dot" class="nuxt__badge-dot"></em>
</div>
<div class="txt" :style="{'color': (currentTabIndex == index ? activeColor : color)}">{{item.text}}</div>
</div>
</div>
</div>
</template>
<script>
export default {
props: {
current: { type: [Number, String], default: 0 },
// 背景颜色
bgcolor: { type: String, default: '#fff' },
// 颜色
color: { type: String, default: '#999' },
// 点击后颜色
activeColor: { type: String, default: '#22d59c' },
// 是否固定
fixed: { type: [Boolean, String], default: false },
// tab选项
tabs: { type: Array, }
},
data() {
return {
currentTabIndex: this.current
}
},
created() {
// 匹配当前页面
const _pagePath = this.$route.path
this.tabs.map((val, index) => {
if(val.pagePath == _pagePath) {
this.currentTabIndex = index
}
})
},
methods: {
switchTabs(index, item) {
this.currentTabIndex = index
this.$emit('click', index)
if(item.pagePath) {
this.$router.push(item.pagePath)
}
}
},
}
</script>
支持自定义背景、颜色/选中颜色、是否固定、点击事件(返回索引值)及自定义每一个选项。
<tab-bar bgcolor="#ddd" @click="tabbarClicked" :tabs="[
{
icon: 'icon-tianjia',
text: 'Home',
},
{
icon: 'icon-shezhi',
text: 'Manage',
badge: 1
},
{
icon: 'icon-male',
text: 'Ucenter',
dot: true
}]"
/>
点击tabbar返回点击选项索引值。
methods: {
tabbarClicked(index) {
this.$toast('tabbar索引:' + index)
},
}
<tab-bar bgcolor="#e07fff" color="#fff" activeColor="#fb4e30" fixed :tabs="[
{
icon: 'icon-face',
text: 'Face',
dot: true,
iconSize: '24px',
},
{
iconImg: 'https://gw.alicdn.com/tfs/TB1CoEwVrvpK1RjSZFqXXcXUVXa-185-144.png',
text: '咸鱼',
dock: true,
dockBg: '#fb4e30',
iconSize: '.64rem',
},
{
icon: 'icon-search',
text: '搜索',
}]"
/>
tabs参数配置
// iconfont图标
icon: 'icon-home'
// 标题
text: '标题'
// 自定义跳转页面
pagePath: '/index'
// 自定义图标图片
iconImg: 'http://www.xxx.com/assets/xxx.png'
// 自定义图标选中图片
selectedIconImg: 'http://www.xxx.com/assets/xxx-on.png'
// 底部中间凸起按钮
dock: true
// 凸起按钮背景,不设置则为activeColor
dockBg: '#09f'
// 图标/图片大小
iconSize: '32px'
// 小圆点数字
badge: 12
// 是否显示小圆点
dot: true
ok,就分享到这里。希望对大家有所帮助,欢迎一起交流讨论哈!
- 上一篇: Vue3.2 中新出的 expose 是做啥用的?
- 下一篇: 踩坑集锦之vue(vue开发踩坑总结)
猜你喜欢
- 2024-10-21 IntersectionObserver: 教你如何实现一个Vue无限滚动的组件
- 2024-10-21 支持服务器端渲染的移动端Vue组件——NutUI
- 2024-10-21 循序渐进Vue+Element 前端应用开发(6)—常规Element界面组件使用
- 2024-10-21 vue动态路由(支持嵌套路由)和动态菜单UI开发框架,无偿源码
- 2024-10-21 1小时搞定卡片拖拽、自动排列交换位置、拖拽数据存取
- 2024-10-21 如何使用 vue + intro 实现后台管理系统的新手引导
- 2024-10-21 零基础入门vue开发(vue开发步骤)
- 2024-10-21 前端路由与vue-router的基本用法(前端路由实现的两种方式)
- 2024-10-21 Electron-vue客户端开发总结(electron-vue官网)
- 2024-10-21 史上最全 vue-router 讲解 !!!(vue,router)
你 发表评论:
欢迎- 367℃用AI Agent治理微服务的复杂性问题|QCon
- 358℃初次使用IntelliJ IDEA新建Maven项目
- 357℃手把手教程「JavaWeb」优雅的SpringMvc+Mybatis整合之路
- 351℃Maven技术方案最全手册(mavena)
- 348℃安利Touch Bar 专属应用,让闲置的Touch Bar活跃起来!
- 346℃InfoQ 2024 年趋势报告:架构篇(infoq+2024+年趋势报告:架构篇分析)
- 345℃IntelliJ IDEA 2018版本和2022版本创建 Maven 项目对比
- 342℃从头搭建 IntelliJ IDEA 环境(intellij idea建包)
- 最近发表
- 标签列表
-
- powershellfor (55)
- messagesource (56)
- aspose.pdf破解版 (56)
- promise.race (63)
- 2019cad序列号和密钥激活码 (62)
- window.performance (66)
- qt删除文件夹 (72)
- mysqlcaching_sha2_password (64)
- ubuntu升级gcc (58)
- nacos启动失败 (64)
- ssh-add (70)
- jwt漏洞 (58)
- macos14下载 (58)
- yarnnode (62)
- abstractqueuedsynchronizer (64)
- source~/.bashrc没有那个文件或目录 (65)
- springboot整合activiti工作流 (70)
- jmeter插件下载 (61)
- 抓包分析 (60)
- idea创建mavenweb项目 (65)
- vue回到顶部 (57)
- qcombobox样式表 (68)
- vue数组concat (56)
- tomcatundertow (58)
- pastemac (61)
本文暂时没有评论,来添加一个吧(●'◡'●)