搞了一天的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. 单源最短路径(dijkstra算法)php实现

    做一个医学项目,当中在病例评分时会用到单源最短路径的算法.单源最短路径的dijkstra算法的思路例如以下: 如果存在一条从i到j的最短路径(Vi.....Vk,Vj),Vk是Vj前面的一顶点.那么( ...

  2. HDOJ 5093 Battle ships 二分图匹配

    二分图匹配: 分别按行和列把图展开.hungary二分图匹配. ... 例子: 4 4 *ooo o### **#* ooo* 按行展开. .. . *ooo o#oo oo#o ooo# **#o ...

  3. Qt 格式化字符串

    Qt字符串格式化性能比较 Qt字符串格式方法有三种, QString::arg(), QString::sprinft()和QStringList::join().今天我做了个简单的性能测试, 希望对 ...

  4. mvc自带的异步表单提交

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...

  5. (转)几种HtmlEncode的区别

    一.C#中的编码 HttpUtility.HtmlDecode.HttpUtility.HtmlEncode与Server.HtmlDecode.Server.HtmlEncode与HttpServe ...

  6. 国外十个出名的 upload 上传组件

    在日常开发中,我们常会用到很多的组件及共用代码提高我们的开发效率.   King MEDIA - $ 17.00 / 11 Sales DNNStore | 6/5/2014 6:06:42 PM|  ...

  7. 《第一行代码》学习笔记34-服务Service(1)

    1.服务是Android中实现程序后台运行的解决方案,适用于执行不需要和用户交互而且要长期运行的任务. 2.服务的运行不依赖于任何用户界面,或切到后台,或用户打开了另外一个应用程序,服务能够保持正常运 ...

  8. 设置cas server使用http非安全协议

    目录 1.tomcat添加https安全协议 2.下载cas server端部署到tomcat上 3.CAS服务器深入配置(连接MYSQL) 4.Apache Shiro 集成Cas作为cas cli ...

  9. HDU 2063 裸奔的二分图最大匹配

    #include <cstdio>#include <cmath>#include <algorithm>#include <iostream>#inc ...

  10. Sql Server 连接池及其用法

    其实我们一直在使用SqlServer的连接池.在连接字符串中,Pooling为是否启用连接池,默认值为true,表示启用. 与连接池相关的两个重要参数是 Min Pool Size和 Max Pool ...