1:编写router.js
 
import Router from "vue-router"
import Vue from "vue"
import router from "./router/router.vue" // 导入
import component from "./component/component.vue"
import databinding from "./databinding/databinding.vue"
import directive from "./directive/directive.vue"
import eventhanding from "./eventhanding/eventhanding.vue"
import stylebinding from "./stylebinding/stylebinding.vue"
import home from "./home.vue"
Vue.use(Router) // 引用
export default new Router({
linkActiveClass: 'active',
routes: [
{ path: '/component', component: component },
{ path: '/databinding', component: databinding },
{ path: '/directive', component: directive },
{ path: '/eventhanding', component: eventhanding },
{ path: '/stylebinding', component: stylebinding },
{ path: '/router/:userId', component: router }, // 路由传值
{ path: '/*', component: home }, // 找不到路由时跳转到这,一般设置为首页
]
})
2:在main.js中注册router
 
import Vue from 'vue'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import App from './App.vue'
import router from './router.js' //
Vue.use(ElementUI)
new Vue({
el: '#app',
router, // 注册router
render: h => h(App)
})
3:路由跳转传参
 
<el-button class="btnstyle" @click="routerClick">路由</el-button>
routerClick() { // 传入跳转的参数
const userId = 123456;
this.$router.push({
path: `/router/${userId}`
});
console.log("点击路由按钮");
},
 
4:接收路由参数
 
data() {
return {
text: this.$route.params.userId
};
},

vue.js-路由的更多相关文章

  1. vue.js路由参数简单实例讲解------简单易懂

    vue中,我们构建单页面应用时候,一定必不可少用到vue-router vue-router 就是我们的路由,这个由vue官方提供的插件 首先在我们项目中安装vue-router路由依赖 第一种,我们 ...

  2. 使用vue.js路由踩到的一个坑Unknown custom element

    在配合require.js使用vue路由的时候,遇到了路由组件报错: “vue.js:597 [Vue warn]: Unknown custom element: <router-link&g ...

  3. Vue.js路由

    有时候,我们在用vue的时候会有这样的需求,比如一个管理系统,点了左边的菜单栏,右边跳转到一个新的页面中,而且刷新的时候还会停留在原来打开的页面. 又或者,一个页面中几个不同的画面来回点击切换,这两种 ...

  4. vue.js路由vue-router

    学习网址:https://segmentfault.com/blog/vueroad 转载至:https://segmentfault.com/a/1190000009350679#articleHe ...

  5. Vue.js路由详解

    有时候,我们在用vue的时候会有这样的需求,比如一个管理系统,点了左边的菜单栏,右边跳转到一个新的页面中,而且刷新的时候还会停留在原来打开的页面. 又或者,一个页面中几个不同的画面来回点击切换,这两种 ...

  6. vue.js路由嵌套

    <!DOCTYPE html> <html> <head> <title></title> <meta charset="u ...

  7. Bug记载2之Vue.JS路由定义的位置

    <!DOCTYPE html><html lang="en"> <head> <meta charset="UTF-8" ...

  8. vue.js路由vue-router(一)——简单路由基础

    前言 vue.js除了拥有组件开发体系之外,还有自己的路由vue-router.在没有使用路由之前,我们页面的跳转要么是后台进行管控,要么是用a标签写链接.使用vue-router后,我们可以自己定义 ...

  9. Vue.js路由管理器 Vue Router

    起步 HTML <script src="https://unpkg.com/vue/dist/vue.js"></script> <script s ...

  10. vue.js路由学习笔记二

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

随机推荐

  1. Python 自动化 第一周

    1.Python简介 1.1.Python介绍 python的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,吉多·范罗苏姆(中文名字:龟叔)为了在阿姆斯特丹打发时 ...

  2. centos6.5时间相关

    时间同步 service ntpdate start 开启网络时间同步

  3. Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) C. Classroom Watch

    http://codeforces.com/contest/876/problem/C 题意: 现在有一个数n,它是由一个数x加上x每一位的数字得到的,现在给出n,要求找出符合条件的每一个x. 思路: ...

  4. 教你用命令行激活win10系统

    对于笔者这样爱自己动手的电脑爱好者来说,当然会选择自己组装一台性价比高的台式电脑,一切都准备就绪了,系统也装好了,就差最后一步了--激活系统. 笔者真的很幸运,在网上找到了一些可以使用的密钥,我装的是 ...

  5. 小技巧-C#文本快速删除空行

    查找:^\s*\n 替换空格 选择正则表达式

  6. 创建类似于Oracle中decode的函数

    -- 创建类似于Oracle中decode的函数create or replace function decode(variadic p_decode_list text[])returns text ...

  7. [LeetCode] Valid Square 验证正方形

    Given the coordinates of four points in 2D space, return whether the four points could construct a s ...

  8. 3.如何搭建Appium自动化测试环境

    整个APP自动化环境安装可以参照虫师博客安装 附以下链接: http://www.cnblogs.com/fnng/category/695788.html 下面介绍运用到工作中遇到的一些问题 1.如 ...

  9. NC帮助文档网址

    NC帮助文档:                https://wenku.baidu.com/view/2d05a77c0b4e767f5acfceb6.html NC方法总结:            ...

  10. servlet之session设置

    商品对象,购物车对象,servlet的实现 商品: package app02d;public class Product {    private int id;    private String ...