zoukankan      html  css  js  c++  java
  • vue-router-4-编程式导航

    想要导航到不同的 URL,用 router.push 方法,会向 history 栈添加一个新的记录

    <router-link> 《==》router.push

    // 字符串
    router.push('home')
    
    // 命名的路由
    router.push({ name: 'user', params: { userId: 123 }})
    
    // 对象
    router.push({ path: 'home' })
    
    // 带查询参数,变成 /register?plan=private
    router.push({ path: 'register', query: { plan: 'private' }})
    //如果提供了 path,params 会被忽略,需完整设置路径:
    const userId = 123;
    router.push({ name: 'user', params: { userId }}) // -> /user/123
    router.push({ path: `/user/${userId}` }) // -> /user/123
    //在 router.push 或 router.replace 中提供 onComplete 和 onAbort 回调作为第二个和第三个参数
    
    router.push(location, onComplete?, onAbort?)//导航成功完成或中止时
    router.replace(location, onComplete?, onAbort?)
    
    //replace它不会向 history 添加新记录
    <router-link :to="..." replace>==》
    router.replace(...)
    router.go(n)
    // 在浏览器记录中前进一步,等同于 history.forward()
    router.go(1)
    
    // 后退一步记录,等同于 history.back()
    router.go(-1)
    
    // 前进 3 步记录
    router.go(3)
    
    // 如果 history 记录不够用,那就默默地失败呗
    router.go(-100)
    router.go(100)
  • 相关阅读:
    PHP“Cannot use object of type stdClass as array”
    JS简单循环遍历json数组的方法
    省市区、民族下拉列表框
    java 代码获取视频时长
    CentOs 相关
    曾经遇过的sql问题
    在线分享代码
    ssm 数据库连接池配置
    代码片段
    java 常见问题
  • 原文地址:https://www.cnblogs.com/avidya/p/7644609.html
Copyright © 2011-2022 走看看