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
Preface Tomcat is a widely used Java web containe...
Code <div class="test"> <div&g...
Note: Since .NET FrameWork cannot be run in core ...
Many friends found that the box model is a square...
Table of contents Preface Instruction Basics Hook...
Why do I want to organize the content in this area...
This article example shares the specific code of ...
I searched a lot online and found that many of th...
Installation introduction under Windows: Check ou...
Table of contents 1. Introduction to Portainer 2....
Reference Documentation Official Docker installat...
Preface: During the project development, we encou...
introduction The company's recent Vue front-e...
Source of the problem As we all know, all network...
1. HBase Overview 1.1 What is HBase HBase is a No...