Purpose: Functions implemented: Create a login page and jump to the home page. The home page includes a menu bar, a top navigation bar, a main body, and a standard background web page format. Click different menus in the menu bar to display different components (different pages). To configure I am using element-ui as a template here Prerequisite: Introduce Execute the command in the project directory: Modify step:
1. Modify the app.vue page Just place a <template> <div id="app"> <router-view></router-view> </div> </template> <script> export default { name: 'App', methods: { } } </script> <style> </style> 2. Create a login page (/views/login/login.vue)The login button here jumps directly to the main page, and the current login page will be completely replaced Login page code <template> <div id="login"> <el-form> <el-row :gutter="20"> <el-col class="title" :offset="9" :span="6"> <h1>A login page</h1> </el-col> </el-row> <el-row :gutter="20"> <el-col class="col-label" :offset="7" :span="4"> <span class="label">Account:</span> </el-col> <el-col :span="4"> <el-input type="text" placeholder="Please enter your account number" v-model="account.username"></el-input> </el-col> </el-row> <el-row :gutter="20"> <el-col class="col-label" :offset="7" :span="4"> <span class="label">Password:</span> </el-col> <el-col :span="4"> <el-input type="password" placeholder="Please enter your password" v-model="account.password"></el-input> </el-col> </el-row> <el-row :gutter="20"> <el-col :offset="8" :span="8"> <span> <a href="#" rel="external nofollow" rel="external nofollow" @click="register" >Register account</a> / <a href="#" rel="external nofollow" rel="external nofollow" @click="resetPwd" >Reset password</a> </span> </el-col> </el-row> <el-row :gutter="20"> <el-col :offset="10" :span="4"> <el-button type="primary" round @click="onSubmit">Login</el-button> </el-col> </el-row> </el-form> </div> </template> <script> export default { name: 'login', data() { return { account: username: '', password: '' } } }, methods: { register() { this.$message({ message: 'It seems that there is no such function', type: 'info' }) }, resetPwd() { this.$message({ message: 'Next life', type: 'success' }) }, onSubmit() { this.$router.push('/index') } } } </script> <style scoped> #login { text-align: center; margin: 0 auto; } .label { height: 40px; line-height: 40px; } .col-label { text-align: right; } .el-row { margin-top: 15px; } .el-button { width: 120px; } .title { margin-top: 10%; } </style> View Code 2.1. Add login page routing in router/index.js{ path: '/', name: 'login', component: () => import('../views/login/login.vue') }, 3. Create the main page (/components/index.vue) The main page is mainly divided into three parts: <template> <el-container style="border: 1px solid #eee"> <el-aside width="200px" style="background-color: rgb(238, 241, 246)"> <el-menu :default-openeds="['1']" :router="true"> <el-submenu index="1"> <template slot="title"><i class="el-icon-message"></i>Navigation 1</template> <el-menu-item-group> <template slot="title">Group 1</template> <el-menu-item index="1-1">Option 1</el-menu-item> <el-menu-item index="1-2">Option 2</el-menu-item> </el-menu-item-group> </el-submenu> </el-menu> </el-aside> <el-container class="table-div"> <el-header style="text-align: right; font-size: 12px"> <el-dropdown> <i class="el-icon-setting" style="margin-right: 15px"></i> <el-dropdown-menu slot="dropdown"> <el-dropdown-item>View</el-dropdown-item> <el-dropdown-item>New</el-dropdown-item> <el-dropdown-item>Delete</el-dropdown-item> </el-dropdown-menu> </el-dropdown> <span>Wang Xiaohu</span> </el-header> <el-main> <table></table> </el-main> </el-container> </el-container> </template> <style> .el-header { background-color: #B3C0D1; color: #333; line-height: 60px; } .el-aside { color: #333; } </style> <script> export default { name: 'index', data() { } } </script> <style> .table-div { width: 100%; } .el-table { height: 100%; } </style> 3.1. Create the main page route{ path: '/index', name: 'index', component: () => import('@/components/index') } At this point, the operation configuration of jumping from the login page to the main page is completed. See the effect. Start the project and visit http://localhost:8080/#/ Click to log in and jump to the home page 4. Modify the homepageMainly modify two parts: menu jump path, main configuration routing view 4.1. Enable menu routing mode and modify the menu jump path Enable 4.2. Add router-view Directly replace the main content with 5. Create two subpagesThe page can be located anywhere as long as the routing address is configured correctly I created Configure the route in { path: '/index', name: 'index', component: () => import('@/components/index'), // Configure the page component for the default route jump of the home page here children: [ // Add child routes { path: 'page', // Note: Do not put a / in front of the path, otherwise it will not jump, I have suffered a loss here name: 'page', components: { // Note that the parameter name has s table: () => import('@/components/first-page') // The table here must be the same as the name of the router-view tag on the home page, so that the routing view on the home page will jump, see 3.2 } }, { path: 'table', name: 'table', components: table: () => import('@/components/first-table') } } ] } The access addresses configured in this way are: localhost:8080/#/index/page, localhost:8080/#/index/table The configuration is complete here, visit the page to test it As you can see, the two menu configurations change the main routing view and control the page components displayed in the view. Configuration Complete This is the end of this article about the details of the nested jump of the vue routing view router-view. For more related vue routing view router-view nested jump content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Use Docker to build a Redis master-slave replication cluster
The content of the written Dockerfile is: FROM py...
Table of contents 1.Json string 1.1Json Syntax 1....
This article uses examples to illustrate the simp...
1. The div css mouse hand shape is cursor:pointer;...
In web development, you often encounter characters...
This article example shares the specific code of ...
Deploy the MySQL environment locally (192.168.1.1...
1. Normal background blur Code: <Style> htm...
We use the translate parameter to achieve movemen...
Demand background: Insert GIF dynamic images into...
Diversifying website layouts is our front-end spe...
I believe everyone is familiar with database inde...
This article shares the installation and configur...
Preface After the project is migrated to .net cor...
Engineering Structure The project is divided into...