Vue implements the method example of tab routing switching component

Vue implements the method example of tab routing switching component

Preface

This article introduces the use of vue-router.js routing that comes with vue to implement the paging switching function. Let's take a look at the detailed implementation code.

The implementation picture is as follows

The following is the implementation code

css:

*{
            margin: 0;
            padding: 0;
        }
        #app ul{
            width: 300px;
            height: 30px;
            list-style: none;
        }
        #app>ul>li{
            width: 100px;
            height: 30px;
            float: left;
        }

html:

<div id="app">
    <ul>
        <li>
            <router-link to="/dyy">First page</router-link>
        </li>
        <li>
            <router-link to="/dey">Second page</router-link>
        </li>
        <li>
            <router-link to="/dsy">Page 3</router-link>
        </li>
    </ul>
    <router-view></router-view>
</div>
 
<template id="DyyDay">
    <div>
        <ul>
            <li>News 01</li>
            <li>News 02</li>
            <li>News 03</li>
        </ul>
    </div>
</template>
 
<template id="DeyDay">
    <div>
        <ul>
            <li>message 01</li>
            <li>message 02</li>
            <li>message 03</li>
        </ul>
    </div>
</template>
 
<template id="DsyDay">
    <div>
        <h1>Home</h1>
        <router-link to="/dsy/home1">home1</router-link>
        <router-link to="/dsy/home2">home2</router-link>
        <router-view></router-view>
    </div>
</template>
 
<template id="home1">
    <h1>I am home1</h1>
</template>
 
<template id="home2">
    <h1>I am home2</h1>
</template>

js.

let Dyy={template:`#DyyDay`};
    let Dey={template:`#DeyDay`};
    let Dsy={template:`#DsyDay`};
    let home1={template:`#home1`};
    let home2={template:`#home2`};
    let router = new VueRouter({
        routes:[
            { path:'/',redirect:"dyy" },
            { path:'/dyy',component:Dyy },
            { path:'/dey',component:Dey },
            { path:'/dsy',component:Dsy,
                children:[
                    {path:'/dsy/home1',component:home1},
                    {path:'/dsy/home2',component:home2}
                ]
            }]
    });
    let app = new Vue({
        router
    }).$mount('#app')

Summarize

This is the end of this article about Vue's implementation of the tab routing switching component. For more related Vue tab routing switching component 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:
  • Complete step record of vue encapsulation TabBar component
  • Encapsulation practice example of Vue.js mobile tab component
  • Detailed explanation of how to use the Vue component tabbar
  • Vue encapsulates a Tabbar component with component routing jump method

<<:  How to notify users of crontab execution results by email

>>:  Detailed explanation of how to view the number of MySQL server threads

Recommend

How to modify the contents of an existing Docker container

1. Docker ps lists containers 2. Docker cp copies...

HTML line spacing setting methods and problems

To set the line spacing of <p></p>, us...

MySQL transaction, isolation level and lock usage example analysis

This article uses examples to describe MySQL tran...

Manual and scheduled backup steps for MySQL database

Table of contents Manual backup Timer backup Manu...

How to operate MySQL database with ORM model framework

What is ORM? ORM stands for Object Relational Map...

js realizes packaging multiple pictures into zip

Table of contents 1. Import files 2. HTML page 3....

vue3 timestamp conversion (without using filters)

When vue2 converts timestamps, it generally uses ...

DHCP Configuration Tutorial in CentOS7 Environment

Table of contents Configuration command steps in ...

Detailed steps for completely uninstalling MySQL 5.7

This article mainly summarizes various problems o...

Quickly solve the Chinese input method problem under Linux

Background: I'm working on asset reporting re...

A brief understanding of the relevant locks in MySQL

This article is mainly to take you to quickly und...

CSS3 animation to achieve the effect of streamer button

In the process of learning CSS3, I found that man...

javascript realizes 10-second countdown for payment

This article shares the specific code of javascri...

How is a SQL statement executed in MySQL?

Table of contents 1. Analysis of MySQL architectu...

SQL serial number acquisition code example

This article mainly introduces the sql serial num...