国产成人精品18p,天天干成人网,无码专区狠狠躁天天躁,美女脱精光隐私扒开免费观看

vue實(shí)現四級導航及驗證碼的方法實(shí)例

發(fā)布時(shí)間:2021-08-17 12:16 來(lái)源: 閱讀:0 作者:打小又皮又鬧 欄目: JavaScript 歡迎投稿:712375056

實(shí)現效果:

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

1.home.vue頁(yè)面

<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>
      <!-- 編程式  導航/路由 -->
      <button @click="fourBtn">four</button>
    </nav>
     <router-view></router-view>
  </div>
</template>
 
<script>
export default {
  data() {
    return {
      name: "首頁(yè)",
      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>
        <!-- 三級路由  出門(mén)在二級路由的界面 -->
        <router-view></router-view>
 
    </div>
</template>
 
<script>
    export default {
        name:'One',
        data() {
            return {
                name: "第一頁(yè)"
            }
        },
        
    }
</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頁(yè)面以及驗證碼實(shí)現

實(shí)現效果圖:

<template>
  <div>
    <h1>{{ name }}</h1>
    <button @click="changeCode">驗證碼</button>
    <img :src="imgCodeUrl" alt="">
  </div>
</template>
 
<script>
export default {
  // 組件的別名  在vue調試的時(shí)候方便查看
  name: "Two_zh",
  data() {
    return {
      name: "第二頁(yè)",
      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頁(yè)面

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

5.four.vue頁(yè)面

<template>
    <div>
        <h1>{{name}}</h1>
 
    </div>
</template>
 
<script>
    export default {
        name:'Four',
        data() {
            return {
                name: "第四頁(yè)"
            }
        },
        created() {
            console.log("第四頁(yè) 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 
            // 第一個(gè)參數是 標簽名  擴展的話(huà)  自己的寫(xiě)的組件   也是標簽名
            // 第二個(gè)參數是  可選的  標簽的屬性配置
            // 第三個(gè)參數是  標簽的內容
            component: {
              render(h) {
                return h("h1", "前端")
              }
            },
          },
          {
            // /默認代表根目錄  #/levl31
            // 不帶斜杠  會(huì )自己拼接 #/one/levl32
            // 使用的時(shí)候統一用命名路由
            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","就是個(gè)美工嗎")
                  }
              }
            },
            //  三 四級路由
            {
              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")
      },
      {
        // 可選參數  \d  數字  字符串就匹配不上
        path: "four/:id(\\d*)?",
        name: 'Four',
        component: () => import("@/views/day/four.vue")
      },
    ]
  }
]
 
const router = new VueRouter({
  routes
})
 
export default router

總結

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

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自本網(wǎng)站內容采集于網(wǎng)絡(luò )互聯(lián)網(wǎng)轉載等其它媒體和分享為主,內容觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如侵犯了原作者的版權,請告知一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容,聯(lián)系我們QQ:712375056,同時(shí)歡迎投稿傳遞力量。

vue
亚洲中文字幕人成乱码| 真人床震高潮全部视频免费| 国产精自产拍久久久久久蜜| chinese少爷男男国产| 亚洲午夜无码久久久久| 亚洲日韩看片无码超清|