This project shares the specific code of Vue+Router+Element to implement a simple navigation bar for your reference. The specific content is as follows Project Structure: Directly on the code: mainly introduce the configuration routing Router ①: Introducing Router (Route Manager) //config.js page //navigation bar import Home from '../components/home' //Homepageimport Index from '../components/index' //Video platform import Vid from '../components/vid_terrace' //Other pages import Rests from '../components/rests' export default { routes:[ { path:'/home', name: 'home', component: Home, }, { /** * home configures the navigation bar, this must be configured otherwise it will jump to a new page * /home/index */ path: '/home', name: 'home', component: Home, redirect: 'index', children: [ { name: 'index', path: '/index', component: Index }, { name: 'vid', path: '/vid', component: Vid }, { name:'rests', path: '/rests', component: Rests } ] } ], // Remove the Vue address# mode:'history' } //index.js page import VueRouter from "vue-router"; import Vue from "vue"; import Config from './config'; Vue.use(VueRouter); let router = new VueRouter(Config); export default router; //main.js page import Vue from 'vue'; import App from './App'; // Import Element-ui import ElementUI from 'element-ui'; import 'element-ui/lib/theme-chalk/index.css'; //Import ./router/index fileimport router from "./router/index"; Vue.config.productionTip = false Vue.use(ElementUI); new Vue({ el: '#app', render: h => h(App), router }) //app.vue page <template> <div id="app"> <!-- The component is a functional component that renders the view component matched by the rendering path. --> <router-view></router-view> </div> </template> <script> export default { name: 'App', components: } } </script> <style> #app { text-align: center; color: #2c3e50; margin-top: 60px; } </style> //home.vue page <template> <!-- Navigation Bar --> <div> <el-menu :default-active="this.$route.path" class="el-menu-demo" mode="horizontal" @select="handleSelect" router background-color="#545c64" text-color="#fff" active-text-color="#ffd04b"> <el-menu-item v-for="(tit,i) in titleList" :key="i" :index="tit.name"> <template>{{ tit.navItem }}</template> </el-menu-item> </el-menu> <el-main class="detailed-content"> <router-view /> </el-main> </div> </template> <script> export default { data() { return { activeIndex: '1', activeIndex2: '1', titleList:[ {name:'index', navItem:'Homepage'}, {name:'vid',navItem:'Video Platform'}, {name:'rests',navItem:'others'}, ] } }, methods: { handleSelect(key, keyPath) { console.log(key, keyPath); } } } </script> <style scoped> </style> Effect picture: It may seem a bit complicated at first glance, because the configuration of Router is a bit messy. In fact, there are only a few lines of code for the navigation bar. If your environment has been set up, you only need to look at the home.vue and config.js files. The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Build a file management system step by step with nginx+FastDFS
>>: Vue+Element realizes paging effect
Table of contents 1. Configure Linux hostname Con...
1. Brigde——Bridge: VMnet0 is used by default 1. P...
This article shares the specific code of JavaScri...
The background color of the table can be set thro...
Moore's Law no longer applies Starting with F...
Preface: As far as I know, currently CSS can only...
This article shares the specific code of JavaScri...
Table of contents 1. Introduction 2. Introduction...
Table of contents 1 element offset series 1.1 Off...
Table of contents 1. Create HTML structure 2. Cre...
The following error message appears when installi...
Table of contents 1. Why do we need unit testing?...
Table of contents 1. this keyword 2. Custom attri...
This article example shares the specific code of ...
Table of contents Preface: 1. Introduction to Use...