手机赚钱怎么赚,给大家推荐一个手机赚钱APP汇总平台:手指乐(http://www.szhile.com/),辛苦搬砖之余用闲余时间动动手指,就可以日赚数百元

  • route-link是在html中静态定义的,也可以在代码中动态跳转:
  1. <!DOCTYPE html>
  2. <html lang="en">
  3.  
  4. <head>
  5. <meta charset="UTF-8">
  6. <title>abc</title>
  7. <script src="https://unpkg.com/vue/dist/vue.js"></script>
  8. <script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
  9. </head>
  10.  
  11. <body>
  12. <div id="app">
  13. <h1>Hello App!</h1>
  14. <!-- 路由出口 -->
  15. <!-- 路由匹配到的组件将渲染在这里 -->
  16. <router-view>
  17. </router-view>
  18. </div>
  19. </body>
  20. <script type="text/javascript">
  21. // 0. 如果使用模块化机制编程,导入 Vue 和 VueRouter,要调用 Vue.use(VueRouter)
  22.  
  23. // 1. 定义(路由)组件。
  24. // 可以从其他文件 import 进来
  25. // const Foo = { template: '<div @onclick="pushtest" href="">Go to Bar</a>' }
  26. // const Bar = { template: '<div @onclick="pushtest" href="">Go to Foo</a>' }
  27.  
  28. const Foo = Vue.extend({
  29. template: '<a @click="pushtest" href="javascript:void(0)">Navigate to bar</a>',
  30. methods: {
  31. pushtest() {
  32. //alert("bar");
  33. this.$router.push({ name: 'bar' });
  34. //alert("fdas");
  35. },
  36. },
  37.  
  38. });
  39.  
  40. const Bar = Vue.extend({
  41. template: '<a @click="pushtest" href="javascript:void(0)">Navigate to foo</a>',
  42. methods: {
  43. pushtest() {
  44. //alert("foo");
  45. this.$router.push({ name: 'foo' });
  46. //alert("fdas");
  47. },
  48. },
  49. });
  50.  
  51. // 2. 定义路由
  52. // 每个路由应该映射一个组件。 其中"component" 可以是
  53. // 通过 Vue.extend() 创建的组件构造器,
  54. // 或者,只是一个组件配置对象。
  55. // 我们晚点再讨论嵌套路由。
  56. const routes = [
  57. { path: '/', redirect: "/bar" },
  58. { path: '/foo', name: "foo", component: Foo },
  59. { path: '/bar', name: "bar", component: Bar },
  60.  
  61. ]
  62.  
  63. // 3. 创建 router 实例,然后传 `routes` 配置
  64. // 你还可以传别的配置参数, 不过先这么简单着吧。
  65. const router = new VueRouter({
  66. routes // (缩写)相当于 routes: routes
  67. })
  68.  
  69. // 4. 创建和挂载根实例。
  70. // 记得要通过 router 配置参数注入路由,
  71. // 从而让整个应用都有路由功能
  72. const app = new Vue({
  73. router, // (缩写)相当于 router: router
  74. // methods: {
  75. // pushtest:function() {
  76. // alert("fdas");
  77. // },
  78. // },
  79. watch: {
  80. $route(to, from) {
  81. //alert(to.path);
  82. //document.getElementById("testzy").innerText = this.$route.params.id;
  83. }
  84. },
  85.  
  86. }).$mount('#app') // 现在,应用已经启动了!
  87. </script>
  88.  
  89. </html>

注意绝对不能写href="",这样执行click跳转后,又会执行href跳转到当前页面

push也可以直接使用path:

  1. this.$router.push('/foo');
  • push会向history添加一条新记录,此时后退会跳转到前一个组件

router.replace(location)跟push功能类似,但是不会向history添加一条新记录,不能后退

router.go(n)

这个方法的参数是一个整数,意思是在 history 记录中向前或者后退多少步,类似 window.history.go(n)。

 
  1. // 在浏览器记录中前进一步,等同于 history.forward()
  2. router.go(1)
  3.  
  4. // 后退一步记录,等同于 history.back()
  5. router.go(-1)
  6.  
  7. // 前进 3 步记录
  8. router.go(3)
  9.  
  10. // 如果 history 记录不够用,那就默默地失败呗
  11. router.go(-100)
  12. router.go(100)

vue路由--使用router.push进行路由跳转的更多相关文章

  1. vue 使用a+ router.push的形式跳转时,地址栏不显示参数

    解决办法: a链接不要写href 属性

  2. vue中this.$router.push()路由传值和获取的两种常见方法

    1.路由传值   this.$router.push() (1) 路由跳转使用router.push()方法,这个方法会向history栈添加一个新纪录,所以,当用户点击浏览器后退按钮时,会回到之前的 ...

  3. vue 之this.$router.push、replace、go的区别

    一.this.$router.push 说明:跳转到指定URL,向history栈添加一个新的记录,点击后退会返回至上一个页面 使用: this.$router.push('/index') this ...

  4. vue 中 this.$router.push() 路由跳转传参 及 参数接收的方法

    传递参数的方法:1.Params 由于动态路由也是传递params的,所以在 this.$router.push() 方法中 path不能和params一起使用,否则params将无效.需要用name ...

  5. Vue中this.$router.push参数获取(通过路由传参)【路由跳转的方法】

    传递参数的方法: 1.Params 由于动态路由也是传递params的,所以在 this.$router.push() 方法中 path不能和params一起使用,否则params将无效.需要用nam ...

  6. router.push query 路由 跳转 传参使用

    this.$router.push({path:'/shop',query:{ goods_name:goods_name, goods_price:goods_price, uid:goods_pr ...

  7. Vue中this.$router.push(参数) 实现页面跳转

    很多情况下,我们在执行点击按钮跳转页面之前还会执行一系列方法,这时可以使用 this.$router.push(location) 来修改 url,完成跳转. push 后面可以是对象,也可以是字符串 ...

  8. Vue中this.$router.push参数获取

    传递参数的方法:1.Params 由于动态路由也是传递params的,所以在 this.$router.push() 方法中path不能和params一起使用,否则params将无效.需要用name来 ...

  9. vue中this.$router.push() 传参

    1  params 传参 注意⚠️:patams传参 ,路径不能使用path 只能使用name,不然获取不到传的数据 this.$router.push({name: 'dispatch', para ...

随机推荐

  1. Pyhon语法字符集报错

    pyhton对语法的字符集,特别的敏感因此我们在写python代码特别要注意.以下代码是个人在学习python中遇见的错误 附:错代码截图1-1 从以上代码中可以看到,似乎代码没有什么问题接下来验证一 ...

  2. 编写TypeScript工具类型,你需要知道的知识

    什么是工具类型 用 JavaScript 编写中大型程序是离不开 lodash 工具的,而用 TypeScript 编程同样离不开工具类型的帮助,工具类型就是类型版的 lodash .简单的来说,就是 ...

  3. if(a)是什么意思

    if(a)等价于 if(a!=0) if(!a)等价于 if(a==0)

  4. 【Java面试】java基础篇

    总结个人的面试经历以及一些网上的的面试题,以供以后面试与巩固java基础. 1.String.StringBuilder和StringBuffer的区别 String用于存储不可变字符串的类,Stri ...

  5. FastDF step by step

    step one 肯定是安装一个FastDF服务了 step two FasDFS配置节点 step third 码代码

  6. typescript step by step interface class

  7. JS基础——ATM机终端程序编写(2.0)

    在1.0版本上,利用数组进行用户的创建,通过调用数组下标,进行密码.余额的使用.新增了切换账户.修改密码的功能 以下为数组版代码. 创建模拟账户 个账户: let user = ["xiao ...

  8. linux--->阿里云centos6.9环境配置安装lnmp

    阿里云centos6.9环境配置安装lnmp mysql安装 本人博客:http://www.cnblogs.com/frankltf/p/8615418.html PHP安装 1.安装依赖关系 yu ...

  9. 微信小程序如何创建云函数并安装wx-server-sdk依赖

    时间:2020/01/23 步骤 1.在微信开发者工具中云函数所在的文件夹的图标与其他文件夹是不同的,如下(第一个是云函数): 如果需要使一个普通文件变为云函数文件夹,需要在project.confi ...

  10. 024.Python模块OS模块

    一 OS模块 对系统进行操作 1.1 popen 可以把运行的结果,这个字符串转化成utf-8这样的编码格式在进行输出 import os res = os.popen("ifconfig& ...