vue.js template模板的使用
使用template實現(xiàn)如下頁面

如上圖.使用了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' // 設(shè)置 鏈接激活時使用的 CSS 類名,默認值: "router-link-active"
});
export default router;總結(jié)
以上所述是小編給大家介紹的vue.js template模板的使用,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關(guān)文章
Vue 項目部署在子目錄下時hash vs history 的真實區(qū)別解析
Vue子目錄部署中,hash模式穩(wěn)定且無需后端配合,而history模式需要后端支持否則容易出問題,子目錄部署下,hash模式天生安全且頁面刷新不會404,而history模式需要正確配置Nginx才能正常工作,本文給大家介紹Vue部署在子目錄下時hash vs history區(qū)別,感興趣的朋友一起看看吧2026-01-01
Vue+vite創(chuàng)建項目關(guān)于vite.config.js文件的配置方法
Vue項目創(chuàng)建時,我們見過vue-cli 創(chuàng)建項目和webpack 創(chuàng)建項目等方式,這篇文章主要介紹了Vue+vite創(chuàng)建項目關(guān)于vite.config.js文件的配置方法,需要的朋友可以參考下2023-06-06
Vue實現(xiàn)Hover功能(mouseover與mouseenter的區(qū)別及說明)
這篇文章主要介紹了Vue實現(xiàn)Hover功能(mouseover與mouseenter的區(qū)別及說明),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-10-10
Vue3?echarts組件化及使用hook進行resize方式
這篇文章主要介紹了Vue3?echarts組件化及使用hook進行resize方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-04-04
ElementUI-Table 表格實現(xiàn)行拖拽效果
在Vue中實現(xiàn)表格拖拽功能,需引入依賴,配置ref、row-key及row-drag-end事件,使用mounted鉤子和key、$nextTick/$set確保數(shù)據(jù)刷新,添加樣式完成拖拽效果,本文介紹ElementUI-Table表格實現(xiàn)行拖拽效果,感興趣的朋友一起看看吧2025-10-10

