current position:Home>Technology sharing | test platform development - Vue router routing design for front-end development
Technology sharing | test platform development - Vue router routing design for front-end development
2022-04-29 12:46:59【Hua Weiyun】
This article is excerpted from the internal textbook of Hogwarts testing college
The route here refers to the path manager between pages , Simply understood as vue-router Is the link path management system .vue-router yes Vue.js The official routing plug-in , It and vue.js It's deeply integrated , Suitable for building single page applications .vue-router Is to map components to routes . stay vue-router Single page application , Is the switching between paths , That is, the switching of components .
vue router Routing configuration
Component design
stay Vue in , Routing is configured in router Medium index.js Configuration in .
for example :
First, in the components Create two Vue Components , Namely SignIn.vue and SignUp.vue. The contents of these two documents are
SignIn.vue
<template> <div class='login-form'> <h1> Sign in </h1> <v-text-field label=" user name "></v-text-field> <v-text-field type="password" label=" password "></v-text-field> <v-btn color='primary'> Sign in </v-btn> <v-btn color='primary' text> register </v-btn> </div></template>
SignUp.vue
<template> <div class='sign-up'> <h1> register </h1> <v-text-field lable=" user name "></v-text-field> <v-text-field lable=" password " type='password'></v-text-field> <v-text-field lable=" mailbox "></v-text-field> <v-btn color='primary'> register </v-btn> <v-btn color='primary' text> To land </v-btn> </div></template>
These two pages are the login interface and the registration interface , And that's where it comes in router Medium index.js File to manage routing .
Routing configuration
First, we find in the existing projects index.js The file of , The default content is as follows :
// Configure routing rules const routes = [ { path: '/', // The root path of the web page , Home page name: 'Home', // Unique identification , Used to identify the role component: Home // Associated components }, { path: '/about', name: 'About', // route level code-splitting // this generates a separate chunk (about.[hash].js) for this route // which is lazy-loaded when the route is visited. component: function () { return import(/* webpackChunkName: "about" */ '../views/About.vue') } }]
Now the above SignIn.vue and SignUp.vue Two components are configured .
First of all, it's in index.js There are two components configured for routing
1、 stay index.js Import these two components
import SignIn from '../components/SignIn.vue'import SignUp from '../components/SignUp.vue'
2、 stay index.js Configure routing information
{ path:'/', # there path:'/' Is the path that the page can access name:'SignIn', # As the identification of this route component:SignIn # Specify components }, { path:'/sign-up', name:'SignUp', component:SignUp }
3、 The next step is how to trigger the jump between pages , First of all, you need to find the... Under the page <script>
Label under methods Create a method , It's called signUp()
.
The code is as follows :
<script>export default { methods: { signUp(){ this.$router.push({name:'SignUp'}) # there name:'SignUp' Is in index.js Routing configuration name } }}
4、 Bind an event to the control , Use here @click='signUp()'
Monitor click events . When you click this button When , It will trigger signUp Method .
<v-btn color='primary' text @click="signUp()"> register </v-btn>
vue router That's all for routing design , You can practice more ~
copyright notice
author[Hua Weiyun],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2022/119/202204291122394455.html
The sidebar is recommended
- Construction and development of automatic test platform based on HTTP runner
- Application of RT thread - use RT thread on stm32l051 (v. conclusion of wireless temperature and humidity sensor)
- Expose Dubbo to HTTP service
- Put the front end into the spring cloud project
- Front end learning day 4 - CSS
- Vue URL jump page with parameters
- JavaScript Chapter 13 traversal of arrays and implicit parameters of function methods
- These CSS efficiency improvement skills, you need to know!
- Beijing has opened the pilot of unmanned operation of passenger cars, and the driverless air outlet has arrived
- Test theory series - Test Case elements and design methods Part II
guess what you like
How to make the peak value of measured output voltage not less than 2V
Hexo quickly set up its own blog
Gee synthetic cloudless landsat-8 and sentry-2 data
Prototype object creation method case JavaScript specific implementation steps
YAF CLI and HTTP access modes
Simple HTML + CSS animation web page production DW simple animation web page production
The correct way for web programmers to make a pink girl series happy birthday blessing web page (HTML + CSS + JS)
HTML + CSS + JS to make simple animation web pages
HTML gourmet web page production DW static web page production div + CSS gourmet web page implementation and production
Programmer 520 Tanabata Valentine's Day confession code HTML + JS + CSS petal photo album web page template programmer confession necessary
Random recommended
- Element notify notification prompt text wrap
- Belkin: it's too early to talk about real wireless space charging
- JavaScript ES6 set (set) type* ω *
- Understand JavaScript function execution process and scope chain
- Java project: nursing home management system (java + springboot + thymeleaf + HTML + JS + MySQL)
- Java project: drug management system (java + springboot + HTML + layui + bootstrap + seals + MySQL)
- An error is reported when installing hexo during hexo deployment. What is the reason and how to solve it (tag git | keyword path)
- [front end basics] Linux command: Project Automation deployment
- Less than 100 or win Porsche, Maserati "special supply" 3.0T technical analysis
- Introduction to basic methods of math built-in objects in JavaScript
- CSS matches the nth element of the parent element
- What is the commercialization process of unmanned robotaxi after China allows driverless steering wheel?
- A lot of trouble, cook also worried: a quarter less than $8 billion
- Ajax realizes no refresh paging (no refresh paging shopping cart source code)
- [flutter topic] 101 what is flutter elements Yyds dry goods inventory
- What is the commercialization process of unmanned robotaxi after China allows driverless steering wheel?
- A lot of trouble, cook also worried: a quarter less than $8 billion
- Element acquisition of data structure c language sequence stack
- Set video label based on Vue
- CSS realizes div width adaptation, and the proportion of height and width is fixed
- How to create JavaScript custom events
- Is there any recommendation for wireless signal and wired signal power amplification circuit?
- Introduction to basic methods of math built-in objects in JavaScript
- 1000km pure electric endurance is meaningless? Then why does the car factory still try its best to extend the endurance?
- [let's implement a simple vite!] Chapter 4 - compiling single file components
- 3-11xss htmlspecialchars bypass demo
- How to conduct architecture design 𞓜 deeply reveal Alibaba cloud serverless kubernetes (2)
- Heapdump performance community special series 7: front door opener of large factory -- Application Practice of fluent
- 1、 HTML base tag
- Don't leave the crane unless necessary! A case of novel coronavirus nucleic acid positive was found in Heshan, Guangdong
- [Architect (Part 20)] self defined template of scaffold and summary of phase I
- How does JavaScript understand this algorithm
- [live review] openharmony knowledge empowerment lesson 2, phase 5 - becoming a community talent
- Understand the basic history and knowledge of HTTP
- Influence of lazy loading of Web front-end training on Web Performance
- Guangxi 2021 Guangxi landscape - blessing Lake Changshou Island
- Responsive gulp Chinese network of web front end
- Twaver-html5 basic learning (26) background
- CSS learning notes [3] floating, not separated from document flow, inheritance and stacking
- Webengine loading local html is invalid, and html is the dynamic address generated by JS, which can be solved