zoukankan      html  css  js  c++  java
  • Vue路由机制

    视图层:

    主要是<router-link>和<router-view>两个标签

    <router-link>执行时会转换成<a>,并根据自己的to属性将路由地址转变成href的值,然后渲染在<router-view>标签中。

    js配置路由的两种写法

    写法一:

    index.js

    Vue.use(Router)
    
    export default new Router({
      routes: [
        {path:'/',component:Home},
        {path:'/detail',component:detail}
      ]
    })

    main.js

    import router from './router/index.js'
    
    new Vue({
      router,
      render: h => h(App)
    }).$mount('#app-box')

    写法二:

    main.js

    import Home from 'xxx'
    import detail from 'xxx'
    
    Vue.use(VueRouter)
    
    const routes = [{  //定义路由表
      path: '/',
      component: Home
    },{
      path: '/detail',
      component: detail
    }]
    
    const router = new VueRouter({创建router管理上面定义好的routes
      routes
    })
    
    new Vue({    //将配置好的router注入Vue根实例中
      router,
      render: h => h(App)
    }).$mount('#app-box')
  • 相关阅读:
    java23种设计模式(五)--组合模式
    elasticsearch删除
    Jedis
    Redis主从复制(含哨兵模式)
    Redis持久化
    Redis基本知识(含数据类型)
    Linux学习(含有常用命令集)
    深入Kafka
    Kafka消费者
    Kafka生产者
  • 原文地址:https://www.cnblogs.com/dengxiaobo/p/7826110.html
Copyright © 2011-2022 走看看