vue.js template模板的使用(仿饿了么布局)

 更新时间:2018年08月13日 14:25:28   作者:至情相遇  
这篇文章主要介绍了vue.js template模板的使用,主要是模仿饿了么布局,用到了4个组件,分别是header.vue,goods.vue,ratings.vue,seller.vue,感兴趣的朋友跟随脚本之家小编一起看看实现代码

使用template实现如下页面(仿饿了么布局)

如上图.使用了4个组件,分别是header.vue,goods.vue,ratings.vue,seller.vue

header.vue代码如下

<template>
   <div class="header">
     我是header头部
  </div>
 </template>
 <script type="text/ecmascript-6">
   export default {
  };
 </script>
<style lang="stylus" rel="stylesheet/stylus">
   .header
     color:#fff
     background:rgba(7,17,27,0.5)
     text-align:center
     height:40px
     line-height:40px
 </style>
goods.vue的代码如下,其他两个类似
<template>
   <div class="goods">
     我是goods组件
  </div>
 </template>
 <script type="text/ecmascript-6">
   export default {
  };
 </script>
<style lang="stylus" rel="stylesheet/stylus">
 </style>

在App.vue文件中,我们使用到了<router-link>标签和<router-view>

代码如下

<template>
   <div id="app">
     <!--头部组件-->
     <v-header></v-header>
     <div class="tab border-1px">
       <div class="tab-item">
         <router-link to="/goods/goods">商品</router-link>
       </div>
       <div class="tab-item">
         <router-link to="/ratings/ratings">评价</router-link>
       </div>
       <div class="tab-item">
         <router-link to="/seller/seller">商家</router-link>
       </div>
     </div>
     <!-- keep-alive:缓存所有的页面,防止重复渲染DOM -->
     <keep-alive>
       <router-view></router-view>
     </keep-alive>
   </div>
 </template>
 <script type="text/ecmascript-6">
   // 引人组件
  import header from '@/components/header/header';
   export default {
     components: {
       'v-header': header
     }
   };
 </script>
<style lang="stylus" rel="stylesheet/stylus">
   @import "./common/stylus/mixin.styl";
  .tab
     display:flex
     width:100%
     height:40px
     line-height:40px
     border-1px(rgba(7,17,27,0.1))
     .tab-item
       flex:1
       text-align:center
       & > a
         display:block
         font-weight:700
         text-decoration:none
         font-size:14px
         color:rgb(77,85,93)
         &.active
           color:yellow
 </style>

 index.js中这样写

import Vue from 'vue';
 import VueRouter from 'vue-router';
 import VueResource from 'vue-resource';
 //引入自定义的组件
import Goods from '@/components/goods/goods';
 import Ratings from '@/components/ratings/ratings';
 import Seller from '@/components/seller/seller';
Vue.use(VueRouter);
 Vue.use(VueResource);
const routers = [{
   path:'/goods/goods',
   name:'goods',
   component:Goods
 },{
   path:'/ratings/ratings',
   name:'ratings',
   component:Ratings
 },{
   path:'/seller/seller',
   name:'seller',
   component:Seller
 }];
const router =new VueRouter({
   mode:'history', //如果不配置 mode,就会使用默认的 hash 模式,该模式下会将路径格式化为 #! 开头。
   routes:routers,
   linkActiveClass : 'active' // 设置 链接激活时使用的 CSS 类名,默认值: "router-link-active"
 });
 export default router;

总结

以上所述是小编给大家介绍的vue.js template模板的使用(仿饿了么布局),希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!

相关文章

  • vite2打包的时候vendor-xxx.js文件过大的解决方法

    vite2打包的时候vendor-xxx.js文件过大的解决方法

    vite2是一个非常好用的工具,只是随着代码的增多,打包的时候 vendor-xxxxxx.js 文件也越来越大,本文主要介绍了vite2打包的时候vendor-xxx.js文件过大的解决方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2022-03-03
  • 基于Vue实现平滑过渡的拖拽排序功能

    基于Vue实现平滑过渡的拖拽排序功能

    这篇文章主要介绍了vue实现平滑过渡的拖拽排序功能,本文通过实例代码给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下
    2019-06-06
  • vuex实现历史记录的示例代码

    vuex实现历史记录的示例代码

    这篇文章主要介绍了vuex实现历史记录的示例代码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2021-05-05
  • 解决Antd 里面的select 选择框联动触发的问题

    解决Antd 里面的select 选择框联动触发的问题

    这篇文章主要介绍了解决Antd 里面的select 选择框联动触发的问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2020-10-10
  • vue2封装webSocket的实现(开箱即用)

    vue2封装webSocket的实现(开箱即用)

    在Vue2中,可以使用WebSocket实时通信,本文主要介绍了vue2封装webSocket的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2023-08-08
  • 在antd4.0中Form使用initialValue操作

    在antd4.0中Form使用initialValue操作

    这篇文章主要介绍了在antd4.0中Form使用initialValue操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2020-11-11
  • 简单的Vue异步组件实例Demo

    简单的Vue异步组件实例Demo

    大家都知道当使用时才装入需要的组件,可以有效的提高首次装入页面的速度。比如在路由切换时,下面这篇文章主要给大家介绍了关于如何实现一个简单的Vue异步组件的相关资料,文中通过示例代码介绍的非常详细,需要的朋友可以参考下。
    2017-12-12
  • vue2中插槽(slot)的基本使用规范

    vue2中插槽(slot)的基本使用规范

    插槽(Slot)是Vue提出来的一个概念,正如名字一样,插槽用于决定将所携带的内容,插入到指定的某个位置,从而使模板分块,具有模块化的特质和更大的重用性,下面这篇文章主要给大家介绍了关于vue2中插槽(slot)的基本使用规范的相关资料,需要的朋友可以参考下
    2022-03-03
  • Ant Design Vue日期组件的时间限制方式

    Ant Design Vue日期组件的时间限制方式

    这篇文章主要介绍了Ant Design Vue日期组件的时间限制方式,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2023-04-04
  • vue动态路由匹配和路由懒加载多种方法详解

    vue动态路由匹配和路由懒加载多种方法详解

    这篇文章主要介绍了vue动态路由匹配和路由懒加载,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2023-06-06

最新评论