码迷,mamicode.com
首页 > 其他好文 > 详细

vue07-router 路由

时间:2018-02-25 11:11:42      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:.com   class   def   temp   load   app   ini   gpo   path   

main.js

vue init webpack //选择router
import router from ‘./router‘
new Vue({
  el: ‘#app‘,
  router,
  components: { App },
  template: ‘<App/>‘
})
// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from ‘vue‘
import App from ‘./App‘
import router from ‘./router‘

Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  el: ‘#app‘,
  router,
  components: { App },
  template: ‘<App/>‘
})

router/index.js

import Vue from ‘vue‘
import Router from ‘vue-router‘
import HelloWorld from ‘@/components/HelloWorld‘
import Contact from ‘@/components/Contact‘
import Friend from ‘@/components/Friend‘

Vue.use(Router)

export default new Router({
  routes: [
    {
      path: ‘/‘,
      name: ‘HelloWorld‘,
      component: HelloWorld
    },
    {
      path: ‘/Contact/:id/:name‘,
      name: ‘Contact‘,
      props : true,//是否接受参数
      component: Contact
    },
    {
      path: ‘/Friend‘,
      name: ‘Friend‘,
      component: Friend
    }
  ]
})

Contact.vue

<template>
    <div>
        <h1>contact</h1>
        {{id}} {{name}}
    </div>
</template>

<script>
    export default {
        props : [
            ‘id‘,
            ‘name‘
        ]
    }
</script>

代码在github上,如果觉得有帮助请给我星星

源代码下载

vue07-router 路由

标签:.com   class   def   temp   load   app   ini   gpo   path   

原文地址:https://www.cnblogs.com/caijw/p/8468670.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!