• vue07-router 路由


    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上,如果觉得有帮助请给我星星

    源代码下载

  • 相关阅读:
    模拟展示动态按钮
    模拟界面请求到web服务器
    bean的生命周期
    structs2的action实现方式
    annotation中的Autowired
    华为笔试题练习
    开发工具
    [转]Linux双向链表的知识
    【转】 嵌入式C语言编程中Inline函数的应用
    打印格式化printf
  • 原文地址:https://www.cnblogs.com/caijw/p/8468670.html
Copyright © 2020-2023  润新知