亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Vue.js路由實現(xiàn)選項卡簡單實例

 更新時間:2019年07月24日 10:35:01   作者:樂碼樂  
這篇文章主要為大家詳細介紹了Vue.js路由實現(xiàn)選項卡簡單實例,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了Vue.js路由實現(xiàn)選項卡的具體代碼,供大家參考,具體內(nèi)容如下

需要實現(xiàn)下圖效果,點擊上方選項卡,切換到不同內(nèi)容的組件:

事先準(zhǔn)備好兩個庫文件(vue.js、vue-router.js),放到對應(yīng)路徑。

1.引入依賴庫

<script src="vue.js" type="text/javascript" charset="GBK"></script>
<script src="vue-router.js" type="text/javascript" charset="GBK"></script>

2.組件創(chuàng)建

const Html = Vue.extend({
      template: '<div><h1>html</h1><p>{{msg}}</p></div>',
      data: function() {
        return {
          msg: 'This is the html vue-router.'
        }
      }
    });
    const Css = Vue.extend({
      template: '<div><h1>CSS</h1><p>{{msg}}</p></div>',
      data(){
       return{
       msg: 'This is the CSS vue-router.'
       }
      }
    });
    const Vue1 = Vue.extend({
      template: '<div><h1>Vue</h1><p>{{msg}}</p></div>',
      data(){
       return{
       msg: 'This is the Vue vue-router.'
       }
      }
    });
    const Javascript = Vue.extend({
      template: '<div><h1>Javascript</h1><p>{{msg}}</p></div>',
      data(){
       return{
       msg: 'This is the Javascript vue-router.'
       }
      }
    });

3.路由創(chuàng)建與映射

const router = new VueRouter({
     routes: [
      { path: '/html', component: Html },
       { path: '/css', component: Css },
       { path: '/vue', component: Vue1 },
       { path: '/javascript', component: Javascript },
       { path: '/', component: Html } //默認(rèn)路徑
     ] 
    });

4.掛在實例

const vm = new Vue({
       router: router 
    }).$mount('#app');

5.頁面<router-link>,to指令跳轉(zhuǎn)到指定路徑

<div id="app">
    <div class="app-tit">
      <router-link to="/html">html</router-link>
      <router-link to="/css">css</router-link>
      <router-link to="/vue">vue</router-link>
      <router-link to="/javascript">javascript</router-link>
    </div>
  <div class="app-con">
     <router-view></router-view>
    </div>      
  </div>

6.所用樣式

 <style>
  body{
    font-family:"Microsoft YaHei";
  }
  #app{
    width: 600px;
    margin: 0 auto;
  }
  .app-tit{
    font-size: 0;
    width: 600px;
  }
  .app-tit .router-link-active {
   background: #09f;
    color: #fff;
  }
  .app-tit a{
    display: inline-block;
    height: 40px;
    line-height: 40px;
    font-size: 16px;
    width: 25%;
    text-align: center;
    background: #ccc;
    color: #333;
    text-decoration: none;
  }
  .app-con div{
    border: 1px solid #ccc;
    height: 400px;
    padding-top: 20px;
  }
  
</style>

完整代碼

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="GBK">
  <title>hello world</title>
  <script src="vue.js" type="text/javascript" charset="GBK"></script>
  <script src="vue-router.js" type="text/javascript" charset="GBK"></script>
</head>
 <style>
  body{
    font-family:"Microsoft YaHei";
  }
  #app{
    width: 600px;
    margin: 0 auto;
  }
  .app-tit{
    font-size: 0;
    width: 600px;
  }
  .app-tit .router-link-active {
   background: #09f;
    color: #fff;
  }
  .app-tit a{
    display: inline-block;
    height: 40px;
    line-height: 40px;
    font-size: 16px;
    width: 25%;
    text-align: center;
    background: #ccc;
    color: #333;
    text-decoration: none;
  }
  .app-con div{
    border: 1px solid #ccc;
    height: 400px;
    padding-top: 20px;
  }
  
</style>
<body>
  <div id="app">
    <div class="app-tit">
      <router-link to="/html">html</router-link>
      <router-link to="/css">css</router-link>
      <router-link to="/vue">vue</router-link>
      <router-link to="/javascript">javascript</router-link>
    </div>
  <div class="app-con">
     <router-view></router-view>
    </div>      
  </div>
  
  <script type="text/javascript">
    const Html = Vue.extend({
      template: '<div><h1>html</h1><p>{{msg}}</p></div>',
      data: function() {
        return {
          msg: 'This is the html vue-router.'
        }
      }
    });
    const Css = Vue.extend({
      template: '<div><h1>CSS</h1><p>{{msg}}</p></div>',
      data(){
       return{
       msg: 'This is the CSS vue-router.'
       }
      }
    });
    const Vue1 = Vue.extend({
      template: '<div><h1>Vue</h1><p>{{msg}}</p></div>',
      data(){
       return{
       msg: 'This is the Vue vue-router.'
       }
      }
    });
    const Javascript = Vue.extend({
      template: '<div><h1>Javascript</h1><p>{{msg}}</p></div>',
      data(){
       return{
       msg: 'This is the Javascript vue-router.'
       }
      }
    });
    const router = new VueRouter({
     routes: [
      { path: '/html', component: Html },
       { path: '/css', component: Css },
       { path: '/vue', component: Vue1 },
       { path: '/javascript', component: Javascript },
       { path: '/', component: Html } //默認(rèn)路徑
     ] 
    });
    const vm = new Vue({
       router: router 
    }).$mount('#app');
  </script>
</body>
</html>

如有錯誤之處,歡迎指出,萬分感謝!

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Vue生態(tài)的新成員Pinia的詳細介紹

    Vue生態(tài)的新成員Pinia的詳細介紹

    本文主要介紹了Vue生態(tài)的新成員Pinia的詳細介紹,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-01-01
  • vue+elementUI組件table實現(xiàn)前端分頁功能

    vue+elementUI組件table實現(xiàn)前端分頁功能

    這篇文章主要為大家詳細介紹了vue+elementUI組件table實現(xiàn)前端分頁功能,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-12-12
  • Vue Promise的axios請求封裝詳解

    Vue Promise的axios請求封裝詳解

    這篇文章主要介紹了Vue Promise的axios請求封裝詳解,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-08-08
  • Vue列表頁渲染優(yōu)化詳解

    Vue列表頁渲染優(yōu)化詳解

    這篇文章主要為大家詳細介紹了Vue列表頁渲染優(yōu)化的操作,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-07-07
  • Vue中使用video.js實現(xiàn)截圖和視頻錄制與下載

    Vue中使用video.js實現(xiàn)截圖和視頻錄制與下載

    這篇文章主要為大家詳細介紹了Vue中如何使用video.js實現(xiàn)截圖和視頻錄制與下載,文中的示例代碼講解詳細,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2024-03-03
  • Vue父子組件之間事件通信示例解析

    Vue父子組件之間事件通信示例解析

    這篇文章主要介紹了React中父子組件通信詳解,在父組件中,為子組件添加屬性數(shù)據(jù),即可實現(xiàn)父組件向子組件通信,文章通過圍繞主題展開詳細的內(nèi)容介紹,具有一定的參考價值,需要的小伙伴可以參考一下
    2023-03-03
  • Vue 自定義指令實現(xiàn)一鍵 Copy功能

    Vue 自定義指令實現(xiàn)一鍵 Copy功能

    指令 (Directives) 是帶有 v- 前綴的特殊特性。這篇文章主要介紹了Vue 自定義指令實現(xiàn)一鍵 Copy的功能,需要的朋友可以參考下
    2019-09-09
  • 關(guān)于vue的npm run dev和npm run build的區(qū)別介紹

    關(guān)于vue的npm run dev和npm run build的區(qū)別介紹

    這篇文章主要介紹了關(guān)于vue的npm run dev和npm run build的區(qū)別介紹,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-01-01
  • Vue.js 和 MVVM 的注意事項

    Vue.js 和 MVVM 的注意事項

    MVVM 是Model-View-ViewModel 的縮寫,它是一種基于前端開發(fā)的架構(gòu)模式,Vue.js 是一個提供 MVVM 風(fēng)格的雙向數(shù)據(jù)綁定的 Javascript 庫,專注于View 層。這篇文章給大家介紹Vue.js 和 MVVM 的注意事項,感興趣的朋友一起看看吧
    2016-11-11
  • Vue.js路由vue-router使用方法詳解

    Vue.js路由vue-router使用方法詳解

    這篇文章主要為大家詳細介紹了Vue.js路由vue-router使用方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-03-03

最新評論