vue.js template模板的使用

 更新时间:2018年08月13日 14:25:29   作者:至情相遇  
这篇文章主要介绍了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模板的使用,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!

相关文章

  • Vue 项目部署在子目录下时hash vs history 的真实区别解析

    Vue 项目部署在子目录下时hash vs history 的真实区别解析

    Vue子目录部署中,hash模式稳定且无需后端配合,而history模式需要后端支持否则容易出问题,子目录部署下,hash模式天生安全且页面刷新不会404,而history模式需要正确配置Nginx才能正常工作,本文给大家介绍Vue部署在子目录下时hash vs history区别,感兴趣的朋友一起看看吧
    2026-01-01
  • Vue.js slot插槽的作用域插槽用法详解

    Vue.js slot插槽的作用域插槽用法详解

    这篇文章主要介绍了Vue.js slot插槽的作用域插槽用法详解,本篇文章通过简要的案例,讲解了该项技术的了解与使用,以下就是详细内容,需要的朋友可以参考下
    2021-09-09
  • Vue+vite创建项目关于vite.config.js文件的配置方法

    Vue+vite创建项目关于vite.config.js文件的配置方法

    Vue项目创建时,我们见过vue-cli 创建项目和webpack 创建项目等方式,这篇文章主要介绍了Vue+vite创建项目关于vite.config.js文件的配置方法,需要的朋友可以参考下
    2023-06-06
  • vue3登录界面适配的二种方法实例代码

    vue3登录界面适配的二种方法实例代码

    这篇文章主要介绍了vue3登录界面适配的二种方法,在Vue.js中使用计算属性和条件渲染来处理,每种方法都有其适用场景,选择哪种方法取决于具体需求,需要的朋友可以参考下
    2024-12-12
  • Vue使用axios出现options请求方法

    Vue使用axios出现options请求方法

    这篇文章主要介绍了Vue使用axios出现options请求,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2019-05-05
  • Vue实现Hover功能(mouseover与mouseenter的区别及说明)

    Vue实现Hover功能(mouseover与mouseenter的区别及说明)

    这篇文章主要介绍了Vue实现Hover功能(mouseover与mouseenter的区别及说明),具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2022-10-10
  • Vue3 echarts组件化及使用hook进行resize方式

    Vue3 echarts组件化及使用hook进行resize方式

    这篇文章主要介绍了Vue3 echarts组件化及使用hook进行resize方式,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2023-04-04
  • 详解在不使用ssr的情况下解决Vue单页面SEO问题

    详解在不使用ssr的情况下解决Vue单页面SEO问题

    这篇文章主要介绍了在不使用ssr的情况下解决Vue单页面SEO问题,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2018-11-11
  • 装饰者模式在日常开发中的缩影和vue中的使用详解

    装饰者模式在日常开发中的缩影和vue中的使用详解

    这篇文章主要为大家介绍了装饰者模式在日常开发中的缩影和vue中的使用详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2022-12-12
  • ElementUI-Table 表格实现行拖拽效果

    ElementUI-Table 表格实现行拖拽效果

    在Vue中实现表格拖拽功能,需引入依赖,配置ref、row-key及row-drag-end事件,使用mounted钩子和key、$nextTick/$set确保数据刷新,添加样式完成拖拽效果,本文介绍ElementUI-Table表格实现行拖拽效果,感兴趣的朋友一起看看吧
    2025-10-10

最新评论