第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定

餓了么vue,項目創(chuàng)建流程代碼篇(路由基本,將父組件和子組件聯(lián)系起來)

標簽:
Vue.js
创建的过程( 二):路由功能实现页面切换

目录结构

图片描述

定义三个子组件,分别是goods,seller,ratings
安装vue-router插件 npm install --save-dev vue-router

// 入口main.js下

import VueRouter from 'vue-router';
import App from './App';
// goods组件
import Goods from './components/goods/goods';
import Seller from './components/seller/seller';
import Ratings from './components/ratings/ratings';
// 全局引用样式
import './common/stylus/index.styl';
/**
 * 入口js  上方引入的是父组件和一个依赖组件
 */
/* eslint-disable no-new */

Vue.use(VueRouter);  // 使用路由插件

/* eslint-disable no-unused-vars */
// 需要一个根组件
let app = Vue.extend(App);
// 实例一个路由,可以拉入自己的配置项
let router = new VueRouter({
  linkActiveClass: 'active'
});

// 配置路由
router.map({
  '/goods': {
    component: Goods
  },
  '/seller': {
    component: Seller
  },
  '/ratings': {
    component: Ratings
  }
});
// 启动路由,配置一个挂载点
router.start(app, '#app');

// 进入页面默认载入板块
router.go('/goods');

子组件goods等可以加内容方便显示

<template>
  <div>内容</div>
</template>
<script type="text/ecmascript-6">
  export default{};
</script>
<style lang='stylus' rel='stylesheet/stylus' type="text/stylus">

</style>

App.vue中使对引入的组件进行样式的设置,注意导入组件之后,进行注册

<!--模板-->
<template>
  <div>
    <v-header></v-header>
    <div class="tab  border-1px">
      <div class="tab-item">
        <!--vue1.0路由引用-->
        <a v-link="{path:'/goods'}">商品</a>
      </div>
      <div class="tab-item">
        <a v-link="{path:'/ratings'}">评论</a>
      </div>
      <div class="tab-item">
        <a v-link="{path:'/seller'}">商家</a>
      </div>
    </div>
    <!--路由的外链 点击了路由触发,页面变化的内容部分-->
    <router-view></router-view>
  </div>
</template>
<!--js脚本-->
<script>
  import header from './components/Header/header';
  export default{
    // 注册header
    components: {
      'v-header': header
    }
  };
</script>
<!--样式-->
<style lang="stylus" rel="stylesheet/stylus" type="text/stylus">
  .tab
    display:flex
    width:100%
    height:40px
    line-height:40px
    border-bottom: 1px solid rgba(7,17,27,0.1)
    .tab-item
      flex:1
      text-align:center
      &>a
        display:block
        text-decoration:none
        font-size:14px
        color:rgb(77, 85, 95)
        &.active
          color:rgb(240, 20, 20)
</style>
點擊查看更多內(nèi)容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優(yōu)質(zhì)文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學(xué)習(xí),寫下你的評論
感謝您的支持,我會繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學(xué)

大額優(yōu)惠券免費領(lǐng)

立即參與 放棄機會
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號

舉報

0/150
提交
取消