首页 > 其他 > 详细

Vue学习手记02-路由创建

时间:2019-07-14 13:21:46      阅读:60      评论:0      收藏:0      [点我收藏+]

1.创建项目
  注意:项目在初始化的时候不要安装vue-router

2.安装路由:
  cnpm install vue-router --save

3.如果在一个模块化工程中使用它,在main.js中必须要通过 Vue.use() 明确地安装路由功能:
  import Vue from ‘vue‘
  import VueRouter from ‘vue-router‘
  Vue.use(VueRouter)

4.main.js创建路由
  const router = new VueRouter({
    routes:[
      {
        path:"/",
        name:"HelloWorld",
        component:HelloWorld
      }
    ]
  })

5.需要显示路由的位置
  <router-view />

6.注入路由对象,在main.js中Vue实例中
   new Vue({
      el: ‘#app‘,
      router,
      components: { App },
      template: ‘<App/>‘
  })


Vue学习手记02-路由创建

原文:https://www.cnblogs.com/somethingWithiOS/p/11183734.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!