当前位置:   article > 正文

vue实现美观大方的动漫、cos、帖子类型网站_vue制作漂亮网页

vue制作漂亮网页

目录

一、先上效果图

1.项目demo预览:点击预览

2.半次元官方截图:

3.项目demo 效果图:

二、 代码实现

1.项目结构截图:

2.路由配置代码:

3.首页实现

三、项目启动说明

四、总结


一、先上效果图

1.项目demo预览:点击预览

参照半次元的榜单-绘画榜、榜单-COS榜、榜单-写作榜、个人中心、登录注册页面,导航栏等,分别实现页面排版、数据交互、基础框架布局搭建以及自定义vue组件合理的封装及使用。在vue项目开发过程中,作者认为很重要的一点就是自定义组件的合理分离封装及使用,这样有利于界面合理排版、合理拆分、合理整合、重复使用、大页面分小页面利于维护等一系列有点。

2.半次元官方截图:

3.项目demo 效果图:

 

 

二、 代码实现

1.项目结构截图:

page为网站布局实现,头部+底部+主页面内容显示容器,views存放具体功能页面,router为路由配置 ,其中头部有两种样式,所以设计了两个头部页面区分,显示容器根据头部的不同也分为两个,其中逻辑一样,仅仅头部复用的不用而区分。

2.路由配置代码:

  1. import Vue from 'vue'
  2. import Router from 'vue-router'
  3. import LayoutOfHome from '@/page/index/home';
  4. import LayoutOfCommon from '@/page/index/common';
  5. Vue.use(Router);
  6. export const constantRoutes = [
  7. {
  8. path: '/index',
  9. component: LayoutOfHome,
  10. redirect: '/ranking',
  11. children: [{
  12. path: 'ranking',
  13. name: '主页',
  14. component: () =>
  15. import( /* webpackChunkName: "views" */ '@/views/home/index'),
  16. children:[
  17. {
  18. path: '/ranking',
  19. name: '首页-榜单',
  20. component: () => import( '@/views/home/ranking/index')
  21. }
  22. ]
  23. }]
  24. },
  25. {
  26. path: '/',
  27. name: '主页',
  28. redirect: '/index'
  29. },
  30. {
  31. path: '/login',
  32. component: LayoutOfCommon,
  33. children: [{
  34. path: '',
  35. name: '登录',
  36. component: () =>
  37. import( /* webpackChunkName: "views" */ '@/page/login/index'),
  38. }]
  39. },
  40. {
  41. path: '/personal',
  42. component: LayoutOfHome,
  43. children: [{
  44. path: '',
  45. name: '个人中心',
  46. component: () =>
  47. import( /* webpackChunkName: "views" */ '@/views/personal/index'),
  48. }]
  49. },
  50. ];
  51. const createRouter = () => new Router({
  52. // mode: 'history', // require service support
  53. scrollBehavior: () => ({
  54. y: 0
  55. }),
  56. routes: constantRoutes
  57. })
  58. const router = createRouter()
  59. // Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
  60. export function resetRouter() {
  61. const newRouter = createRouter()
  62. router.matcher = newRouter.matcher // reset router
  63. }
  64. export default router

3.首页实现

首页轮播图+ 菜单作为首页通用布局(/home/index.vue,看下图),ranking里面的index.vue作为榜单具体功能页面实现,可以看上面路由配置属性理解: component: LayoutOfHome,这种思维布局可以层层嵌套下去,只要配合 <router-view></router-view>标签使用即可。

/home/index.vue 代码实现布局:

  1. <template>
  2. <div class="rank-index">
  3. <div class="dm-carousel banner-inner" style="width:1200px;height:250px">
  4. <div class="slick-slider slick-initialized">
  5. <div class="slick-list" style="height: 253px;">
  6. <el-carousel height="253px">
  7. <el-carousel-item v-for="item in banners" :key="item">
  8. <el-image :src="item"></el-image>
  9. </el-carousel-item>
  10. </el-carousel>
  11. </div>
  12. </div>
  13. </div>
  14. <div class="rank-index-navbar">
  15. <div class="home-navbar">
  16. <a v-for="(item,index) in menus" :key="index" :class="'home-navbar-item '+(item.path === path?'active':'')" @click="selTab(item)">{{item.name}}</a>
  17. </div>
  18. </div>
  19. <router-view></router-view>
  20. </div>
  21. </template>
  22. <script>
  23. export default {
  24. data() {
  25. return {
  26. banners: [
  27. require('../../../public/img/banner1.jpg'),
  28. require('../../../public/img/banner2.jpg'),
  29. require('../../../public/img/banner3.jpg'),
  30. require('../../../public/img/banner4.jpg'),
  31. require('../../../public/img/banner5.jpg'),
  32. ],
  33. path:'/ranking',
  34. menus: [
  35. {name:'推荐',path:'/recommend'},
  36. {name:'关注',path:'/follow'},
  37. {name:'榜单',path:'/ranking'},
  38. {name:'绘画',path:'/draw'},
  39. {name:'COS',path:'/cos'},
  40. {name:'小说',path:'/novel'},
  41. {name:'问答',path:'/QAndA'}
  42. ]
  43. };
  44. },
  45. mounted() {
  46. let that = this;
  47. setInterval(function(){
  48. that.path = that.$router.currentRoute.path;
  49. },1000)
  50. },
  51. methods: {
  52. selTab(item){//标签切换
  53. this.path = item.path;
  54. this.$router.push({path: item.path});
  55. },
  56. }
  57. };
  58. </script>
  59. <style scoped>
  60. .rank-index {
  61. width: 1200px;
  62. margin: 0 auto;
  63. }
  64. .banner-inner {
  65. background-color: #fff;
  66. border-radius: 5px;
  67. margin: 12px auto 0;
  68. overflow: hidden;
  69. }
  70. .dm-carousel {
  71. position: relative;
  72. }
  73. .dm-carousel .slick-slider {
  74. width: 100%;
  75. height: 100%;
  76. }
  77. .dm-carousel .slick-slider {
  78. position: relative;
  79. display: block;
  80. -webkit-box-sizing: border-box;
  81. box-sizing: border-box;
  82. -webkit-user-select: none;
  83. -moz-user-select: none;
  84. -ms-user-select: none;
  85. user-select: none;
  86. -ms-touch-action: pan-y;
  87. touch-action: pan-y;
  88. -webkit-tap-highlight-color: transparent;
  89. }
  90. .dm-carousel .slick-slider .slick-list, .dm-carousel .slick-slider .slick-track {
  91. -webkit-transform: translateZ(0);
  92. transform: translateZ(0);
  93. }
  94. .dm-carousel .slick-list {
  95. position: relative;
  96. display: block;
  97. overflow: hidden;
  98. margin: 0;
  99. padding: 0;
  100. }
  101. .rank-index .rank-index-navbar {
  102. height: 48px;
  103. margin: 12px auto;
  104. border-radius: 6px;
  105. -webkit-box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.05);
  106. box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.05);
  107. background-color: #fff;
  108. display: -webkit-box;
  109. display: -ms-flexbox;
  110. display: flex;
  111. -webkit-box-align: center;
  112. -ms-flex-align: center;
  113. align-items: center;
  114. }
  115. .home-navbar {
  116. margin: 0 auto;
  117. display: -webkit-box;
  118. display: -ms-flexbox;
  119. display: flex;
  120. }
  121. .home-navbar .home-navbar-item:not(:last-child) {
  122. padding-right: 48px;
  123. }
  124. .home-navbar .home-navbar-item {
  125. display: block;
  126. font-size: 16px;
  127. color: #252526;
  128. cursor: pointer;
  129. -webkit-transition: color .12s linear;
  130. transition: color .12s linear;
  131. line-height: 1.5;
  132. }
  133. a {
  134. text-decoration: none;
  135. color: #366cd9;
  136. }
  137. .home-navbar .home-navbar-item:hover {
  138. color: #fa4b8b;
  139. }
  140. .home-navbar .home-navbar-item.active {
  141. font-weight: 700;
  142. color: #fa4b8b;
  143. }
  144. .home-navbar .home-navbar-item:hover {
  145. cursor: pointer;
  146. }
  147. </style>

三、项目启动说明

项目是传统vue项目,实现需要安装node js,然后依次成功执行

npm install

npm run dev

顺利的话就这么简单,当然,遇到问题,直接call me(私聊作者获取帮助,作者一直在帮助了很多的小伙伴)

四、总结

当然项目还有很多细节,不是一两句话可以简述的。最快的就是拿到源码去动手操作!

第一步暂时到这里,关注作者,及时了解更多好项目!如果你也有好的案例,欢迎分享出来,说不定下一个demo就ta了。

获取源码 或 如需帮助,通过博客后面名片+作者即可!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/840248
推荐阅读
相关标签
  

闽ICP备14008679号