美文网首页
Vue.js 路由

Vue.js 路由

作者: Hitman_Agent_47 | 来源:发表于2019-07-08 10:07 被阅读0次

    声明式导入

    import Router from 'vue-router'
    

    以 ES6 方式导入 vue 原生路由组件

    插件安装

    Vue.use(Router)
    

    因为 vue-router 被定义为插件,所以在使用之前需要手动 Vue.use()一下
    该操作必须发生在 Vue 对象实例化之前,多次 use 只会安装一次,详见:Vue.use API

    使用方式

    方式 作用
    this.$route 当前路由 (this 表示 Vue 对象)
    this.$route.params.xxx 路由参数 path: '/foo/:xxx'
    this.$router.push('/a/b/c') 编程式跳转
    <router-view/> 路由声明中对应 component 的占位符,用于替换该组件
    <router-link/> 用于生成一个<a/> 标签,to 属性用于 path:to 属性用于 name
    this.$route.query URL的查询字符串
    this.$route.hash # 后面的东西(包含#

    相关文章

      网友评论

          本文标题:Vue.js 路由

          本文链接:https://www.haomeiwen.com/subject/cbvnhctx.html