An example of how Vue implements four-level navigation and verification code

An example of how Vue implements four-level navigation and verification code

Effect:

First create five vue interfaces

1.home.vue page

<template>
  <div id="home-wrapper">
    <h1>{{ name }}</h1>
    <nav>
      <!-- The exit of the secondary router is in the interface of the primary router-->
      <router-link to="/one">one</router-link>
      <router-link :to="{ name: 'Two' }">two</router-link>
      <router-link :to="threeObj">three</router-link>
      <!-- Programmatic Navigation/Routing -->
      <button @click="fourBtn">four</button>
    </nav>
     <router-view></router-view>
  </div>
</template>
 
<script>
export default {
  data() {
    return {
      name: "Home",
      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 interface

<template>
    <div>
        <h1>{{name}}</h1>
        <ul>
            <li>
                <router-link to="/levl31">web</router-link>
            </li>
            <li>
                <router-link :to="{name:'name32'}">backend</router-link>
            </li>
            <li>
                <!-- Using named routes is more convenient in multi-level routing-->
                <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'}">Level 3 Router-4</router-link>
            </li>
        </ul>
        <!-- The third-level router exits the interface of the second-level router-->
        <router-view></router-view>
 
    </div>
</template>
 
<script>
    export default {
        name:'One',
        data() {
            return {
                name: "First Page"
            }
        },
        
    }
</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 page and verification code implementation

Result diagram:

<template>
  <div>
    <h1>{{ name }}</h1>
    <button @click="changeCode">Verification code</button>
    <img :src="imgCodeUrl" alt="">
  </div>
</template>
 
<script>
export default {
  // The component's alias is convenient for viewing during Vue debugging name: "Two_zh",
  data() {
    return {
      name: "Page 2",
      imgCodeUrl:""
    };
  },
  methods: {
    // Get the verification code changeCode() {
        // /api is the proxy configuration in 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("Verification code interface:",res);
        })
        .catch((e) => {
          console.log("Error:", e);
        });
    },
  },
};
</script>
 
<style lang="less" scoped>
</style>

4. three.vue page

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

5.four.vue page

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

Then configure the routes:

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 creacteElement means to create a virtual Dom/label Vnode 
            // The first parameter is the tag name extension. If the component you write is also the tag name // The second parameter is the optional attribute configuration of the tag // The third parameter is the content of the tag component: {
              render(h) {
                return h("h1", "frontend")
              }
            },
          },
          {
            // /Default represents the root directory#/levl31
            // Without slash, it will be concatenated automatically#/one/levl32
            //Use named routing path: "levl32"
            name: "name32",
            component: {
              render(h) {
                return h("h1", "Backend")
                }
              },
            },
            {
              path:"/one?levl33",
              name:"name33",
              component:{
                render(h) {
                  return h("h1", "Artificial Intelligence")
                  }
              }
            },
            {
              path:"/one/levl34",
              name:"name34",
              component:{
                render(h) {
                  return h("h1","Just an artist")
                  }
              }
            },
            //Level 3 and 4 routing {
              path:"level35",
              name:"name35",
              component:()=>import("@/views/Home.vue"),
              //Fourth level routing 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")
      },
      {
        // Optional parameter \d Numeric string will not match path: "four/:id(\\d*)?",
        name: 'Four',
        component: () => import("@/views/day/four.vue")
      },
    ]
  }
]
 
const router = new VueRouter({
  routes
})
 
export default router

Summarize

This is the end of this article about Vue's implementation of four-level navigation and verification code. For more relevant Vue four-level navigation and verification code content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Vue realizes the navigation bar effect (selected state refresh does not disappear)
  • How to implement nav navigation bar in Vue
  • Vue2.0 realizes the navigation menu switching effect
  • Vue implements navigation bar menu
  • Very practical vue navigation hook
  • VUE implements the method of keeping the scroll monitoring navigation bar on top
  • Simple implementation of the 60-second countdown function of the vue verification code
  • vue implements the registration function of sending SMS verification code through mobile phone
  • VUE implements image verification code function
  • Vue generates a random verification code sample code

<<:  How to install Nginx in CentOS

>>:  A brief understanding of the three uses of standard SQL update statements

Recommend

HTML optimization speeds up web pages

Obvious HTML, hidden "public script" Th...

A Brief Analysis of Subqueries and Advanced Applications in MySql Database

Subquery in MySql database: Subquery: nesting ano...

Example of pre-rendering method for Vue single page application

Table of contents Preface vue-cli 2.0 version vue...

CSS realizes the scene analysis of semi-transparent border and multiple border

Scenario 1: To achieve a semi-transparent border:...

CSS implements 0.5px lines to solve mobile compatibility issues (recommended)

【content】: 1. Use background-image gradient style...

Teach you how to subcontract uniapp and mini-programs (pictures and text)

Table of contents 1. Mini Program Subcontracting ...

Connector configuration in Tomcat

JBoss uses Tomcat as the Web container, so the co...

React tsx generates random verification code

React tsx generates a random verification code fo...

How to insert weather forecast into your website

We hope to insert the weather forecast into the w...

Web designers also need to learn web coding

Often, after a web design is completed, the desig...

Detailed explanation of MySQL master-slave replication and read-write separation

Article mind map Why use master-slave replication...

How to add automatic completion commands for docker and kubectl on Mac

Introduction to kubectl kubectl is a command line...

Installation process of zabbix-agent on Kylin V10

1. Download the installation package Download add...

A brief discussion on the magic of parseInt() in JavaScript

cause The reason for writing this blog is that I ...