Vue + vue-router
搞了一天的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的更多相关文章
- 三、vue之router
三.vue之router 此时vue的脚手架.创建项目已经完成. ... vue的运行流程 index.html-->main.js-->App.vue-->router/index ...
- Vue中router两种传参方式
Vue中router两种传参方式 1.Vue中router使用query传参 相关Html: <!DOCTYPE html> <html lang="en"> ...
- 四 Vue学习 router学习
index.js: 按需加载组件: const login = r => require.ensure([], () => r(require('@/page/login')), 'log ...
- vue 中router.go;router.push和router.replace的区别
vue 中router.go:router.push和router.replace的区别:https://blog.csdn.net/div_ma/article/details/79467165 t ...
- 【vue】 router.beforeEach
import store from '@/store' const Vue = require('vue') const Router = require('vue-router') Vue.use( ...
- vue & this.$router.resolve
vue & this.$router.resolve gotoAutoUpdate (query = {}) { const { href } = this.$router.resolve({ ...
- vue & vue router & dynamic router
vue & vue router & dynamic router https://router.vuejs.org/guide/essentials/dynamic-matching ...
- vue & vue router & match bug
vue & vue router & match bug match bugs solution name must be router https://stackoverflow.c ...
- Vue中router路由的使用、router-link的使用(在项目中的实际运用方式)
文章目录 1.先看router中的index.js文件 2.router-link的使用 3.实现的效果 前提:router已经安装 1.先看router中的index.js文件 import Vue ...
- Vue Vue.use() / Vue.component / router-view
Vue.use Vue.use 的作用是安装插件 Vue.use 接收一个参数 如果这个参数是函数的话,Vue.use 直接调用这个函数注册组件 如果这个参数是对象的话,Vue.use 将调用 ins ...
随机推荐
- 基于bootstrap的datatable控件
https://editor.datatables.net/release/DataTables/extras/Editor/examples/bootstrap.htmlhttps://github ...
- coco2d-html5制作弹弓射鸟第一部分---橡皮筋
一.写在前面的话 最近在学习cocos2d-html5方面的知识,一直想从事游戏方面的工作,自己也找了好多资料.网上关于cocos2d-html5的教程真的不多,也只有自己摸索,慢慢看示例代码.由于本 ...
- sqlserver,执行生成脚本时“引发类型为“System.OutOfMemoryException”的异常”(已解决)
sqlserver,执行生成脚本时“引发类型为“System.OutOfMemoryException”的异常”(已解决) 出现此错误主要是因为.sql的脚本文件过大(一般都超过100M)造成内存无法 ...
- Mysqldb连接Mysql数据库(转)
python操作mysql数据库 Python 标准数据库接口为 Python DB-API,Python DB-API为开发人员提供了数据库应用编程接口. Python 数据库接口支持非常多的数据库 ...
- 关于ubuntu16.04给firefox安装flash的补充
这两天把自己的老笔记本安装了ubuntu的16.04版本,关于给firefox安装flash player的方法,网上有很多,但不知道是版本还是其它原因,他们文章都出现目录错误的问题,我个人由于是ub ...
- 利用ajax从txt读取数据
html代码: <div id="news"></div> txt: [ {"id":"1", "news ...
- Intent 意图 结构 简介
Intent简介 官方解释: An intent is an abstract description of an operation操作 to be performed展示.表演. It can b ...
- A.indexOf(array[i])表达的含义
userAgentInfo.indexOf(Agents[v]): //A.indexOf(array[i]):A元素是否存在于数组array里面:如果存在就会返回对应的下标,如果不存在则返回-1. ...
- web前端之文件上传
前言 最近太忙一直没时间认真的写博客(哈哈哈),最近pm提一个需求,移动端需要一个上传图片的功能,允许多选.删除.预览.点击查看大图并可以滑动.虽然听起来很多,但是这个功能在web上实现过啊,使用we ...
- ASP.Net用jQuery ajax实现页面局部刷新
刚开始的时候使用asp的updatepanel控件实现局部刷新,而且在本地运行正确,但是部署到服务器上就变成整个页面全部刷新了.服务器用的是Windows server2000,本地机子上用的是win ...