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

深入理解vue2.0路由如何配置問題

 更新時間:2017年07月18日 17:19:43   作者:燦爾哈擦蘇  
本篇文章主要介紹了vue2.0路由配置問題,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

這兩天學習了Vue.js 感覺路由這個地方知識點挺多的,而且很重要,所以,今天添加一點小筆記。

項目基本手腳架搭建完畢后,建一個router文件夾,里面配置一個index.js文件。

文件內(nèi)容:

npm install vue-router vue-resource --save-dev(安裝 vue 路由模塊vue-router和網(wǎng)絡(luò)請求模塊vue-resource)

import Vue from 'vue' 
import Router from 'vue-router' (----引入路由---注釋說明) 
import About from '@/components/about'(--這些需要引入的是components文件夾下面創(chuàng)建的一些模板---相對路徑----about代表about.vue模塊) 
import Home from '@/components/home' 
import Brand from '@/components/brand' 
import Company from '@/components/company' 
import Connect from '@/components/connect' 
import Main from '@/components/main' 
import Join from '@/components/join' 
import News from '@/components/news' 
import Products from '@/components/products' 
import son1 from '@/components/son1' 
import son2 from '@/components/son2' 
import list from '@/components/list' 
import newList from '@/components/newList' 
import culture from '@/components/culture' 
import certification from '@/components/certification' 
import zhuanjia from '@/components/zhuanjia' 
Vue.use(Router) (--使用---) 
 
export default new Router({ 
 routes: [ 
  { 
   path: '/main', 
   name: 'main', 
   component: Main 
  },-------------------------------- 
  { path: '/',           這里是路由重定向,比如頁面加載時候進入首頁 
   redirect: '/main'          (比如給路由一個選中后的樣式為紅色 那么這里就能用到了---.router-link-active{樣式}) 
  },--------------------------------- 
  {---------------------這里是配置子路由 
   path: '/brand', 
   name: 'brand', 
   component: Brand, 
   children: [ 
    { 
     path: '/', 
     name: 'newList', 
     component: newList 
    }, 
    { 
     path: '/brand/culture', 
     name: 'culture', 
     component: culture 
    }, 
    { 
     path: '/brand/certification', 
     name: 'certification', 
     component: certification 
    }, 
    { 
     path: '/brand/zhuanjia', 
     name: 'zhuanjia', 
     component: zhuanjia 
    } 
   ] 
  }, 
  { 
   path: '/about', 
   name: 'about', 
   component: About 
  }, 
  { 
   path: '/company', 
   name: 'company', 
   component: Company 
  }, 
  { 
   path: '/connect', 
   name: 'connect', 
   component: Connect 
  }, 
  { 
   path: '/home', 
   name: 'home', 
   component: Home 
  }, 
  { 
   path: '/join', 
   name: 'join', 
   component: Join, 
   children: [ 
    { 
     path: '/', 
     name: 'son1', 
     component: son1 
    }, 
    { 
     path: '/join/son2', 
     name: 'son2', 
     component: son2 
    } 
   ] 
  }, 
  { 
   path: '/list', 
   name: 'list', 
   component: list 
  }, 
  { 
   path: '/news', 
   name: 'news', 
   component: News 
  }, 
  { 
   path: '/products', 
   name: 'products', 
   component: Products 
  } 
 ] 
}) 

接下來就是在每一個模塊文件中加入這樣的一句話暴露出去:

<script> 
export default { 
 name: 'about' ---自定義模塊名字 
} 
</script> 

在app中我們可以這樣寫:

 <template> 
 <div id="app1" class="pagebox"> 
    <div style="clear:both;"></div> 
    <ul class="index-tap"> 
      <li><router-link to="/main">首頁<p></p></router-link></li> 
      <li><router-link to="/about">關(guān)于我們<p></p></router-link></li> 
      <li><router-link to="/products">產(chǎn)品專區(qū)<p></p></router-link></li> 
      <li><router-link to="/news">新聞資訊<p></p></router-link></li> 
    </ul> 
    <ul class="index-tap"> 
      <li><router-link to="/company">企業(yè)風采<p></p></router-link></li> 
      <li><router-link to="/join">招商加盟<p></p></router-link></li> 
      <li><router-link to="/connect">聯(lián)系我們<p></p></router-link></li> 
      <li><router-link to="/brand">品牌介紹<p></p></router-link></li> 
    </ul> 
    <div style="clear:both;"></div> 
    <router-view transition transition-mode="out-in"></router-view> 
    <div style="clear:both;"></div> 
    <ul class="index-footer clearx"> 
      <li v-on:click="showph = !showph">電話</li> 
      <li v-on:click="showmap = !showmap">地圖</li> 
      <li v-on:click="showd = !showd">分享</li> 
      <!-- JiaThis Button BEGIN --> 
      <transition name="slide-fade"> 
      <div class="jiathis_style_32x32 share" v-show="showd"> 
        <a class="jiathis_button_qzone"></a> 
        <a class="jiathis_button_tsina"></a> 
        <a class="jiathis_button_tqq"></a> 
        <a class="jiathis_button_weixin"></a> 
        <a class="jiathis_button_renren"></a> 
      </div> 
      </transition> 
      <!-- JiaThis Button END --> 
      <transition name="slide-fade"> 
      <div class="share sharephone" v-show="showph"> 
        18305452462 
      </div> 
      </transition> 
      <transition name="slide-fade"> 
      <div class="share showmap" v-show="showmap"> 
        <ditu></ditu>---------------------------------自定義模板 
      </div> 
      </transition> 
    </ul> 
    <div class="fuceng" v-if="showmap"></div> 
 </div> 
</template> 
 
<script> 
import ditu from '@/components/home' 
export default { 
 name: 'app', 
 data () { 
  return { 
   search: '', 
   showd: false, 
   showph: false, 
   showmap: false 
  } 
 }, 
 mounted () { 
  this.init() 
 }, 
 methods: { 
  Search () { 
   if (this.search !== '') { 
    this.$router.push({ 
     path: '/list', 
     query: { 
      serInfo: this.search 
     } 
    }) 
   } else { 
    alert('請輸入搜索內(nèi)容') 
   } 
  }, 
  init: function () { 
   let url = 'http://v3.jiathis.com/code/jia.js' 
   let script = document.createElement('script') 
   script.setAttribute('src', url) 
   document.getElementsByTagName('head')[0].appendChild(script) 
  } 
 }, 
 components: { 
  ditu 
 } 
} 
</script> 

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

相關(guān)文章

  • vue中對接Graphql接口的實現(xiàn)示例

    vue中對接Graphql接口的實現(xiàn)示例

    本文主要介紹了vue中對接Graphql接口的實現(xiàn)示例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2021-05-05
  • 在vue.config.js中優(yōu)化webpack配置的方法

    在vue.config.js中優(yōu)化webpack配置的方法

    在日常開發(fā)中我們離不開打包工具webpack,但是不同的配置會影響我們項目的運行構(gòu)建時間,也會影響打包之后項目包的大小,這篇文章記錄一下我使用過的可以優(yōu)化webpack的配置,需要的朋友可以參考下
    2024-05-05
  • 深入理解vue中的$set

    深入理解vue中的$set

    這篇文章主要介紹了深入理解vue中的$set,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-06-06
  • 談談我在vue-cli3中用預渲染遇到的坑

    談談我在vue-cli3中用預渲染遇到的坑

    這篇文章主要介紹了談談我在vue-cli3中用預渲染遇到的坑,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-04-04
  • vue卡片式點擊切換圖片組件使用詳解

    vue卡片式點擊切換圖片組件使用詳解

    這篇文章主要為大家詳細介紹了vue卡片式點擊切換圖片組件的使用方法,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-06-06
  • vue-cli3.0項目打包后如何修改訪問后端地址

    vue-cli3.0項目打包后如何修改訪問后端地址

    這篇文章主要介紹了vue-cli3.0項目打包后如何修改訪問后端地址,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-03-03
  • 解決vant中 tab欄遇到的坑 van-tabs

    解決vant中 tab欄遇到的坑 van-tabs

    這篇文章主要介紹了解決vant中 tab欄遇到的坑 van-tabs,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-11-11
  • 關(guān)于vue-router路由的傳參方式params query

    關(guān)于vue-router路由的傳參方式params query

    這篇文章主要介紹了關(guān)于vue-router路由的傳參方式params query,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-10-10
  • Vue echarts畫甘特圖流程詳細講解

    Vue echarts畫甘特圖流程詳細講解

    這篇文章主要介紹了Vue echarts畫甘特圖流程,甘特圖(Gantt chart)又稱為橫道圖、條狀圖(Bar chart)。其通過條狀圖來顯示項目、進度和其他時間相關(guān)的系統(tǒng)進展的內(nèi)在關(guān)系隨著時間進展的情況
    2022-09-09
  • Vue3+TypeScript+printjs實現(xiàn)標簽批量打印功能的完整過程

    Vue3+TypeScript+printjs實現(xiàn)標簽批量打印功能的完整過程

    最近在做vue項目時使用到了print-js打印,這里給大家分享下,這篇文章主要給大家介紹了關(guān)于Vue3+TypeScript+printjs實現(xiàn)標簽批量打印功能的完整過程,文中通過代碼介紹的非常詳細,需要的朋友可以參考下
    2024-09-09

最新評論