一 安装对应版本的VueRouter
二在main.js做相关操作
import Vue from 'vue' import App from './App.vue' //引入路由配置文件 import router from './router/index.js' Vue.config.productionTip = false //引入实例对象 new Vue({ el:"#app", render: h => h(App), router })
三在index.js 配置路由
import Vue from 'vue' import VueRouter from 'vue-router' import AllThings from '../components/AllThings' import Hot from '../components/Hot' import Sport from '../components/Sport' Vue.use(VueRouter) const routes=[ { path:'/AllThings', component:AllThings, },{ path:'/Hot', component:Hot, },{ path:'/sport', component:Sport, } ] export default new VueRouter({ routes })
四在app页面使用
<template> <div id="app"> <router-link to="/AllThings"> <span class="layui-btn">综合</span></router-link> <router-link to="/Hot"> <span class="layui-btn">热门</span></router-link> <router-link to="/sport"> <span class="layui-btn">体育</span></router-link> <div class="layui-container"> <router-view></router-view> </div> </div> </template>
标签:Vue,Hot,vue,VueRouter,使用,import,AllThings,路由 From: https://www.cnblogs.com/nice2018/p/17901807.html