Vue+Router+Element to implement a simple navigation bar

Vue+Router+Element to implement a simple navigation bar

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:
  • ElementUI complex top and left navigation bar implementation example
  • vue+element-ui implements the head navigation bar component
  • Element-ui sample code for implementing responsive navigation bar
  • Solution for highlighting the vue+element navigation bar
  • vue elementUI uses tabs to link with the navigation bar
  • Detailed explanation of how to use the navigation bar to jump to the route in element-ui
  • Implementation of default expansion function of navigation bar when using ElementUI in Vue
  • Vue2.0 elementUI makes breadcrumb navigation bar
  • ElementUI+named view to achieve complex top and left navigation bar

<<:  Build a file management system step by step with nginx+FastDFS

>>:  Vue+Element realizes paging effect

Recommend

How to build Apr module for tomcat performance optimization

Preface Tomcat is a widely used Java web containe...

Vue implements local storage add, delete and modify functions

This article example shares the specific code of ...

Detailed explanation of docker visualization graphics tool portainer

Table of contents 1. Introduction to Portainer 2....

Examples of two ways to implement a horizontal scroll bar

Preface: During the project development, we encou...

Summary of pitfalls in importing ova files into vmware

Source of the problem As we all know, all network...

Hbase Getting Started

1. HBase Overview 1.1 What is HBase HBase is a No...