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

Detailed introduction to linux host name configuration

Table of contents 1. Configure Linux hostname Con...

Three networking methods and principles of VMware virtual machines (summary)

1. Brigde——Bridge: VMnet0 is used by default 1. P...

HTML table tag tutorial (7): background color attribute BGCOLOR

The background color of the table can be set thro...

JavaScript implements circular carousel

This article shares the specific code of JavaScri...

Use of filter() array filter in JS

Table of contents 1. Introduction 2. Introduction...

Detailed explanation of three commonly used web effects in JavaScript

Table of contents 1 element offset series 1.1 Off...

JavaScript exquisite snake implementation process

Table of contents 1. Create HTML structure 2. Cre...

Getting Started with Front-End Vue Unit Testing

Table of contents 1. Why do we need unit testing?...

Detailed explanation of this reference and custom properties in JavaScript

Table of contents 1. this keyword 2. Custom attri...

Vuex implements simple shopping cart function

This article example shares the specific code of ...

Detailed explanation of MySQL user rights management

Table of contents Preface: 1. Introduction to Use...