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

vue實現(xiàn)四級導(dǎo)航及驗證碼的方法實例

 更新時間:2021年07月13日 10:35:27   作者:打小又皮又鬧  
我們在做項目經(jīng)常會遇到多級導(dǎo)航這個需求,所以下面這篇文章主要給大家介紹了關(guān)于vue實現(xiàn)四級導(dǎo)航及驗證碼的相關(guān)資料,文章通過示例代碼介紹的非常詳細,需要的朋友可以參考下

實現(xiàn)效果:

 首先創(chuàng)建五個vue界面

1.home.vue頁面

<template>
  <div id="home-wrapper">
    <h1>{{ name }}</h1>
    <nav>
      <!-- 二級路由的出口 在一級路由的界面里面 -->
      <router-link to="/one">one</router-link>
      <router-link :to="{ name: 'Two' }">two</router-link>
      <router-link :to="threeObj">three</router-link>
      <!-- 編程式  導(dǎo)航/路由 -->
      <button @click="fourBtn">four</button>
    </nav>
     <router-view></router-view>
  </div>
</template>
 
<script>
export default {
  data() {
    return {
      name: "首頁",
      threeObj: {
        name: "Three",
      },
    };
  },
  methods: {
    fourBtn() {
      var userId = 6789;
      this.$router.push({
        path: `four/${userId}`,
      });
    },
  },
};
</script>
 
<style lang="less" scoped>
#home-wrapper{
  nav{
    display: flex;
    a{
      flex: 1;
      background-color: antiquewhite;
      height: 50px;
      line-height: 50px;
    }
  }
}
</style>

2.one.vue界面

<template>
    <div>
        <h1>{{name}}</h1>
        <ul>
            <li>
                <router-link to="/levl31">web</router-link>
            </li>
            <li>
                <router-link :to="{name:'name32'}">后端</router-link>
            </li>
            <li>
                <!-- 使用命名路由 在多級路由里面  比較方便 -->
                <router-link :to="{name:'name33'}">AI</router-link>
            </li>
            <li>
                <router-link to="/one/levl34">UI</router-link>
            </li>
            <li>
                <router-link :to="{name:'name35'}">三級路由-4</router-link>
            </li>
        </ul>
        <!-- 三級路由  出門在二級路由的界面 -->
        <router-view></router-view>
 
    </div>
</template>
 
<script>
    export default {
        name:'One',
        data() {
            return {
                name: "第一頁"
            }
        },
        
    }
</script>
 
<style lang="less" scoped>
ul{
    list-style: none;
    display: flex;
    width: 100%;
    margin-left: -40px;
 
}
li{
    flex: 1;
    background-color: orange;
    height: 50px;
    line-height: 50px;
 
}
 
</style>

 3.two.vue頁面以及驗證碼實現(xiàn)

實現(xiàn)效果圖:

<template>
  <div>
    <h1>{{ name }}</h1>
    <button @click="changeCode">驗證碼</button>
    <img :src="imgCodeUrl" alt="">
  </div>
</template>
 
<script>
export default {
  // 組件的別名  在vue調(diào)試的時候方便查看
  name: "Two_zh",
  data() {
    return {
      name: "第二頁",
      imgCodeUrl:""
    };
  },
  methods: {
    // 獲取驗證碼
    changeCode() {
        // /api 是在vue.config.js 里面代理配置
      const url = "api/v1/captchas";
    //   const url = "https://elm.cangdu.org/v1/captchas";
      this.axios
        .post(url, {})
        .then((res) => {
            this.imgCodeUrl =res.data.code 
          console.log("驗證碼接口:",res);
        })
        .catch((e) => {
          console.log("錯誤:", e);
        });
    },
  },
};
</script>
 
<style lang="less" scoped>
</style>

4. three.vue頁面

<template>
    <div>
        <h1>{{name}}</h1>
 
    </div>
</template>
 
<script>
    export default {
        name:'three',
        data() {
            return {
                name: "第三頁"
            }
        },
        
    }
</script>
 
<style lang="less" scoped>
 
</style>

5.four.vue頁面

<template>
    <div>
        <h1>{{name}}</h1>
 
    </div>
</template>
 
<script>
    export default {
        name:'Four',
        data() {
            return {
                name: "第四頁"
            }
        },
        created() {
            console.log("第四頁 created:",this.$route)
        },
    }
</script>
 
<style lang="less" scoped>
 
</style>

然后配置路由:

import Vue from 'vue'
import VueRouter from 'vue-router'
import Home2 from '@/views/day/home.vue'
 
Vue.use(VueRouter)
 
const routes = [
  {
    path: "/",
    name: 'home2',
    component: Home2,
    redirect: "/one",
    children: [
      {
        path: "/one",
        name: 'One',
        component: () => import("@/views/day/one.vue"),
        children: [
          {
            path: '/levl31',
            // h creacteElemet 的意思 創(chuàng)建 虛擬Dom/標簽 Vnode 
            // 第一個參數(shù)是 標簽名  擴展的話  自己的寫的組件   也是標簽名
            // 第二個參數(shù)是  可選的  標簽的屬性配置
            // 第三個參數(shù)是  標簽的內(nèi)容
            component: {
              render(h) {
                return h("h1", "前端")
              }
            },
          },
          {
            // /默認代表根目錄  #/levl31
            // 不帶斜杠  會自己拼接 #/one/levl32
            // 使用的時候統(tǒng)一用命名路由
            path: "levl32",
            name: "name32",
            component: {
              render(h) {
                return h("h1", "后端")
                }
              },
            },
            {
              path:"/one?levl33",
              name:"name33",
              component:{
                render(h) {
                  return h("h1", "人工智能")
                  }
              }
            },
            {
              path:"/one/levl34",
              name:"name34",
              component:{
                render(h) {
                  return h("h1","就是個美工嗎")
                  }
              }
            },
            //  三 四級路由
            {
              path:"level35",
              name:"name35",
              component:()=>import("@/views/Home.vue"),
              // 四級路由
              children:[
                {
                  path:"boy",
                  name:"Boy",
                  component:()=>import("@/views/boy.vue")
                },
                {
                  path:"girl",
                  name:"Girl",
                  component:()=>import("@/views/girl.vue")
                }
 
              ]
 
            }
        ]
      },
      {
        path: "/two",
        name: 'Two',
        component: () => import("@/views/day/two.vue")
      },
      {
        path: "/three",
        name: 'Three',
        component: () => import("@/views/day/three.vue")
      },
      {
        // 可選參數(shù)  \d  數(shù)字  字符串就匹配不上
        path: "four/:id(\\d*)?",
        name: 'Four',
        component: () => import("@/views/day/four.vue")
      },
    ]
  }
]
 
const router = new VueRouter({
  routes
})
 
export default router

總結(jié)

到此這篇關(guān)于vue實現(xiàn)四級導(dǎo)航及驗證碼的文章就介紹到這了,更多相關(guān)vue四級導(dǎo)航及驗證碼內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 在vue項目中(本地)使用iconfont字體圖標的三種方式總結(jié)

    在vue項目中(本地)使用iconfont字體圖標的三種方式總結(jié)

    這篇文章主要介紹了在vue項目中(本地)使用iconfont字體圖標的三種方式總結(jié),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-09-09
  • 解決vue中的無限循環(huán)問題

    解決vue中的無限循環(huán)問題

    這篇文章主要介紹了解決vue中的無限循環(huán)問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-07-07
  • 在vue-cli創(chuàng)建的項目中使用sass操作

    在vue-cli創(chuàng)建的項目中使用sass操作

    這篇文章主要介紹了在vue-cli創(chuàng)建的項目中使用sass操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-08-08
  • 淺析Vue下的components模板使用及應(yīng)用

    淺析Vue下的components模板使用及應(yīng)用

    這篇文章主要介紹了Vue下的components模板的使用及應(yīng)用,本文通過代碼介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-11-11
  • WebPack配置vue多頁面的技巧

    WebPack配置vue多頁面的技巧

    這篇文章主要介紹了WebPack配置vue多頁面的方法,本文給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下
    2018-05-05
  • vue中正確使用jsx語法的姿勢分享

    vue中正確使用jsx語法的姿勢分享

    這篇文章主要給大家介紹了關(guān)于vue中正確使用jsx的相關(guān)資料,JSX就是Javascript和XML結(jié)合的一種格式,React發(fā)明了JSX,利用HTML語法來創(chuàng)建虛擬DOM,當遇到<,JSX就當HTML解析,遇到{就當JavaScript解析,需要的朋友可以參考下
    2021-07-07
  • vue?element-ui的table列表中展示多張圖片(可放大)效果實例

    vue?element-ui的table列表中展示多張圖片(可放大)效果實例

    這篇文章主要給大家介紹了關(guān)于vue?element-ui的table列表中展示多張圖片(可放大)效果的相關(guān)資料,文中通過代碼示例介紹的非常詳細,需要的朋友可以參考下
    2023-08-08
  • vue終極性能優(yōu)化方案(解決首頁加載慢問題)

    vue終極性能優(yōu)化方案(解決首頁加載慢問題)

    最近在做項目中前端采用Vue技術(shù),發(fā)現(xiàn)首頁加載速度非常之慢,下面這篇文章主要給大家介紹了關(guān)于vue終極性能優(yōu)化方案,主要解決首頁加載慢問題,需要的朋友可以參考下
    2022-02-02
  • LogicFlow插件使用前準備詳解

    LogicFlow插件使用前準備詳解

    這篇文章主要為大家介紹了LogicFlow插件使用前準備詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-01-01
  • vue  composition-api 封裝組合式函數(shù)的操作方法

    vue  composition-api 封裝組合式函數(shù)的操作方法

    在 Vue 應(yīng)用的概念中,“組合式函數(shù)”(Composables) 是一個利用 Vue 的組合式 API 來封裝和復(fù)用有狀態(tài)邏輯的函數(shù),這篇文章主要介紹了vue  composition-api 封裝組合式函數(shù)的操作方法,需要的朋友可以參考下
    2022-10-10

最新評論

电白县| 钦州市| 永新县| 桓仁| 凤城市| 沙田区| 阿鲁科尔沁旗| 敦化市| 阿鲁科尔沁旗| 稷山县| 隆回县| 镇宁| 峨眉山市| 新宁县| 陆川县| 潞西市| 黄浦区| 霞浦县| 崇信县| 桦南县| 郓城县| 宜良县| 沁源县| 张家口市| 屯留县| 南和县| 静宁县| 渝中区| 彰化市| 长海县| 会东县| 新巴尔虎右旗| 奉化市| 塔城市| 玉溪市| 福安市| 五大连池市| 合川市| 通城县| 磐安县| 广东省|