最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Vue.js路由實(shí)現(xiàn)選項(xiàng)卡簡(jiǎn)單實(shí)例

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

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

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

事先準(zhǔn)備好兩個(gè)庫文件(vue.js、vue-router.js),放到對(duì)應(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.掛在實(shí)例

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>

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

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

相關(guān)文章

  • 基于vue-resource jsonp跨域問題的解決方法

    基于vue-resource jsonp跨域問題的解決方法

    下面小編就為大家分享一篇基于vue-resource jsonp跨域問題的解決方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2018-02-02
  • vue結(jié)合vant實(shí)現(xiàn)聯(lián)動(dòng)效果

    vue結(jié)合vant實(shí)現(xiàn)聯(lián)動(dòng)效果

    這篇文章主要為大家詳細(xì)介紹了vue結(jié)合vant實(shí)現(xiàn)聯(lián)動(dòng)效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-01-01
  • Vue vxe-table使用問題收錄小結(jié)

    Vue vxe-table使用問題收錄小結(jié)

    這篇文章主要為大家介紹了Vue vxe-table使用問題收錄小結(jié),有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-09-09
  • Vue零基礎(chǔ)入門之模板語法與數(shù)據(jù)綁定及Object.defineProperty方法詳解

    Vue零基礎(chǔ)入門之模板語法與數(shù)據(jù)綁定及Object.defineProperty方法詳解

    這篇文章主要介紹了Vue初學(xué)基礎(chǔ)中的模板語法、數(shù)據(jù)綁定、Object.defineProperty方法等基礎(chǔ),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-09-09
  • vue 組件使用中的一些細(xì)節(jié)點(diǎn)

    vue 組件使用中的一些細(xì)節(jié)點(diǎn)

    這篇文章主要介紹了vue 組件使用中的一些細(xì)節(jié)點(diǎn),大概有兩大細(xì)節(jié)點(diǎn),本文通過基礎(chǔ)實(shí)例給大家介紹的非常詳細(xì),需要的朋友參考下吧
    2018-04-04
  • Vue3配置vite.config.js解決跨域問題的方法

    Vue3配置vite.config.js解決跨域問題的方法

    跨域一般出現(xiàn)在開發(fā)階段,由于線上環(huán)境前端代碼被打包成了靜態(tài)資源,因而不會(huì)出現(xiàn)跨域問題,這篇文章主要給大家介紹了關(guān)于Vue3配置vite.config.js解決跨域問題的相關(guān)資料,需要的朋友可以參考下
    2024-07-07
  • 淺談Vue+Ant Design form表單的一些坑

    淺談Vue+Ant Design form表單的一些坑

    本文主要介紹了淺談Vue+Ant Design form表單的一些坑,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-06-06
  • vue清除動(dòng)態(tài)路由的問題記錄

    vue清除動(dòng)態(tài)路由的問題記錄

    項(xiàng)目中往往都是添加動(dòng)態(tài)路由,如何刪除已經(jīng)添加進(jìn)來的路由往往被忽視,為此這里做一下記錄,感興趣的朋友跟隨小編一起看看吧
    2023-10-10
  • Vite配置路徑別名的簡(jiǎn)單實(shí)現(xiàn)方法

    Vite配置路徑別名的簡(jiǎn)單實(shí)現(xiàn)方法

    Vite項(xiàng)目中我們可以手動(dòng)將src路徑設(shè)置**@**路徑別名,可以省下很多引入路徑的冗余路徑,下面這篇文章主要給大家介紹了關(guān)于Vite配置路徑別名的簡(jiǎn)單實(shí)現(xiàn)方法,需要的朋友可以參考下
    2023-04-04
  • vue頁面使用js實(shí)現(xiàn)前端打印功能

    vue頁面使用js實(shí)現(xiàn)前端打印功能

    這篇文章主要介紹了vue頁面使用js實(shí)現(xiàn)前端打印功能,文中通過圖文結(jié)合的方式給大家講解的非常詳細(xì),對(duì)大家實(shí)現(xiàn)打印功能有一定的幫助,需要的朋友可以參考下
    2024-05-05

最新評(píng)論

江川县| 梁河县| 丹巴县| 三明市| 临颍县| 兴海县| 天柱县| 信丰县| 中西区| 辽中县| 海伦市| 卢氏县| 马边| 阿拉善右旗| 双牌县| 乌海市| 三明市| 公安县| 鹤岗市| 饶阳县| 乌拉特前旗| 荃湾区| 进贤县| 锡林郭勒盟| 抚宁县| 顺昌县| 蓝田县| 沈阳市| 蒲城县| 寿阳县| 密山市| 于田县| 平塘县| 化德县| 康保县| 鸡泽县| 合作市| 尼勒克县| 浏阳市| 乐陵市| 宣化县|