搞了一天的element-ui,vue-router,把侧栏的导航菜单搞了出来后,试着在菜单上加入链接,研究了下官方提供的文档,发现要使用vue-route。

在项目中安装好vue-route, 对照vue-router的文档及网上的例子,在项目中加入了路由功能,搞了一天,试了无数次,链接一直无效!!!

项目起始页 index.html 代码

 <div id="mainApp">
<h1>Hello App!</h1>
<p>
<router-link to="/">Go to Index</router-link>
<router-link to="/users">Go to Users</router-link>
</p>
<router-view></router-view>
</div>

在main.js中这样配置正常:

import Vue from 'vue'
import VueRouter from "vue-router";

Vue.use(VueRouter); const Index = { template: '<div>Index</div>' }
const User = { template: '<div>User</div>' }
const routes = [
{ path: '/', component: Index },
{ path: '/users', component: User }
] const router = new VueRouter({
routes
})
console.log(routes); const app = new Vue({
router
}).$mount('#mainApp')

点击链接显示文字:

把路由路径独立出来放在单独的文件夹中,路由就不起作用:

//main.js
import Vue from 'vue'
import VueRouter from "vue-router";
import RoutesMap from './routes/' Vue.use(VueRouter); const router = new VueRouter({
RoutesMap
})
console.log(RoutesMap); const app = new Vue({
router
}).$mount('#mainApp')
//  routes/index.js
const Index = { template: '<div>Index</div>' }
const User = { template: '<div>User</div>' } const routes = [
{ path: '/', component: Index },
{ path: '/users', component: User }
] export default routes

点击链接没有动静,还没法调试:

真要吐血了。。。

2016年11月25日15:25:23 路由问题已解决:

//main.js
import Vue from 'vue'
import VueRouter from "vue-router";
import RoutesMap from './routes/' Vue.use(VueRouter); //需要使用一个具名数组
const router = new VueRouter({
routes: RoutesMap
})
console.log(RoutesMap); const app = new Vue({
router
}).$mount('#mainApp')

Vue + vue-router的更多相关文章

  1. 三、vue之router

    三.vue之router 此时vue的脚手架.创建项目已经完成. ... vue的运行流程 index.html-->main.js-->App.vue-->router/index ...

  2. Vue中router两种传参方式

    Vue中router两种传参方式 1.Vue中router使用query传参 相关Html: <!DOCTYPE html> <html lang="en"> ...

  3. 四 Vue学习 router学习

    index.js: 按需加载组件: const login = r => require.ensure([], () => r(require('@/page/login')), 'log ...

  4. vue 中router.go;router.push和router.replace的区别

    vue 中router.go:router.push和router.replace的区别:https://blog.csdn.net/div_ma/article/details/79467165 t ...

  5. 【vue】 router.beforeEach

    import store from '@/store' const Vue = require('vue') const Router = require('vue-router') Vue.use( ...

  6. vue & this.$router.resolve

    vue & this.$router.resolve gotoAutoUpdate (query = {}) { const { href } = this.$router.resolve({ ...

  7. vue & vue router & dynamic router

    vue & vue router & dynamic router https://router.vuejs.org/guide/essentials/dynamic-matching ...

  8. vue & vue router & match bug

    vue & vue router & match bug match bugs solution name must be router https://stackoverflow.c ...

  9. Vue中router路由的使用、router-link的使用(在项目中的实际运用方式)

    文章目录 1.先看router中的index.js文件 2.router-link的使用 3.实现的效果 前提:router已经安装 1.先看router中的index.js文件 import Vue ...

  10. Vue Vue.use() / Vue.component / router-view

    Vue.use Vue.use 的作用是安装插件 Vue.use 接收一个参数 如果这个参数是函数的话,Vue.use 直接调用这个函数注册组件 如果这个参数是对象的话,Vue.use 将调用 ins ...

随机推荐

  1. 三、Solr多核心及分词器(IK)配置

    多核心的概念 多核心说白了就是多索引库.也可以理解为多个"数据库表" 说一下使用multicore的真实场景,比若说,产品搜索和会员信息搜索,不使用多核也没问题,这样带来的问题是 ...

  2. StringBuffer和StringBuilder使用方法比較

    StringBuffer是字符串缓冲区,是一个容器. 特点: 1,长度是可变化的. 2,能够字节操作多个数据类型. 3,终于会通过toString方法变成字符串. C create U update ...

  3. Qt Creator实现状态栏显示

    在程序主窗口Mainwindow中,有菜单栏,工具栏,中心部件和状态栏.前面几个已经讲过了,这次讲解状态栏的使用. 程序中有哪些不明白的类或函数,请自己查看帮助. 1.我们在mainwindow.h中 ...

  4. POJ 1386 有向图欧拉通路

    题意:给你一些字符串,这些字符串可以首位相接(末位置如果和另一个字符串的首位置相同的话就可以相连) .然后问你是否可以全部连起来. 思路:就是取出每个字符串的首尾位置,然后求出出度和入度,根据有向欧拉 ...

  5. C#_Socket网络编程实现的简单局域网内即时聊天,发送文件,抖动窗口。

    最近接触了C#Socket网络编程,试着做了试试(*^__^*) 实现多个客户端和服务端互相发送消息 发送文件抖动窗口功能 服务端: using System; using System.Collec ...

  6. js获得url的参数

    网上找的一段代码,非常好用,现在难以找到原作者,但是非常感谢!/**   * 获取当前URL参数值  * @param name  参数名称  * @return  参数值   */ function ...

  7. hdu 5188

    it's a  dp  difficult problem 试想如果我们遇见这样一道题,: 有n道题目,每道题有一个得分v和用时t: 我们要得够w分:用时最少  怎么做?? 这是一个裸奔的01背包 如 ...

  8. Jade学习笔记

    初学nodejs,折腾过用handlebars做模板,后来隔了一段重新学习,用了jade,真心简洁……记录一些学习笔记,以备复习. jade是基于缩进的,所以tab与space不能混用: 属性的设置: ...

  9. mongodb安装指南

    mongodb安装 1.解压mongodb-win32-i386-1.8.1.zip ,创建路径C:\Program Files\mongodb ,将解压后的Bin文件Copy to 此文件夹下 2. ...

  10. C# 获取计算机 信息

    /// <summary> /// 获取本机 机器名 /// </summary> /// <returns></returns> public sta ...