vue2.0 + vux (一)Header 组件
1.main.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | import Vue from 'vue' import FastClick from 'fastclick' import VueRouter from 'vue-router' import App from './App' // 自定义的路由文件 import router from './router' // 解决300ms延迟问题 FastClick.attach(document.body) Vue.config.productionTip = false /* eslint-disable no-new */ new Vue({ el: '#app-box' , router, template: '<App/>' , components: { App } }) |
2.路由 router/index.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | import Vue from 'vue' import Router from 'vue-router' // 首页 import Home from '@/pages/Home/Home' // 我的设置 import MySettings from '@/pages/MySettings/MySettings' Vue.use(Router) // 路由配置 export default new Router({ routes: [ // 首页 { path: '/' , name: 'Home' , component: Home }, // 我的设置 { path: '/mySettings' , name: 'MySettings' , component: MySettings }, { path: '/home' , redirect: '/' }, { path: '*' , redirect: '/' }, ] }) |
3.主页面 App.vue
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | <template> <div id= "app" > <!-- 视图层 --> <router-view></router-view> </div> </template> <script> export default { // } </script> <style lang= "less" > @ import '~vux/src/styles/reset.less' ; body { background-color: #fbf9fe; line-height: 1.2; } </style> |
4.Header 组件
Header.vue
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | <!-- 顶部 标题栏 --> <template> <div> <!-- 标题栏 --> <x-header :left-options= "{showBack: false}" style= "background-color:#00CC66;" >{{tag}}</x-header> </div> </template> <script> // 引入组件 import { XHeader, Tabbar, TabbarItem } from 'vux' export default { name: 'AppHeader' , data(){ return { tag: '首页' , showMenus: false } }, components: { XHeader, Tabbar, TabbarItem } } </script> <style lang= "less" scoped> .tabbar{ background-color: #00CC66; height: 50px; position: relative; } </style> |
5.页面调用 Home.vue
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | <!-- 首页 --> <template> <div> <!-- 顶部 标题栏 --> <app-header></app-header> </div> </template> <script> import AppHeader from '../../components/Header' export default { name: 'Home' , components: { AppHeader }, data(){ return { // } } } </script> <style lang= "less" scoped></style> |
6.效果图
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】凌霞软件回馈社区,携手博客园推出1Panel与Halo联合会员
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何统计不同电话号码的个数?—位图法
· C#高性能开发之类型系统:从 C# 7.0 到 C# 14 的类型系统演进全景
· 从零实现富文本编辑器#3-基于Delta的线性数据结构模型
· 记一次 .NET某旅行社酒店管理系统 卡死分析
· 长文讲解 MCP 和案例实战
· C#高性能开发之类型系统:从 C# 7.0 到 C# 14 的类型系统演进全景
· 管理100个小程序-很难吗
· 基于Blazor实现的运输信息管理系统
· 如何统计不同电话号码的个数?—位图法
· 微信支付功能的设计实现与关键实践(UniApp+Java)全代码