良许Linux教程网 干货合集 详解vue-router使用实例

详解vue-router使用实例

vue-router是Vue.js官方的路由插件,它和vue.js是深度集成的,适合用于构建单页面应用。vue的单页面应用是基于路由和组件的,路由用于设定访问路径,并将路径和组件映射起来。

详解vue-router使用实例

main.js

// 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'
import './assets/css/common.css'

Vue.config.productionTip = false

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

router文件夹里面的index.js

import Vue from 'vue'
import Router from 'vue-router'
import home from '../components/home'    //这里可以选择2种写法,一种是写在这里,一种是写在component里面,看下方代码~

Vue.use(Router)

export default new Router({
     mode:'history',
     routes: [
       {
         path: '/',
         component: home
       },
       {
           path:'/pagevue',
           component:pagevue => require(['../components/childCom/pagevue.vue'], pagevue),
       },
       {
           path:'/nextpagevue',
           component:nextpagevue => require(['../components/childCom/nextpagevue.vue'], nextpagevue),
       }
   ]
})

home.vue

pagevue.vue

nextpagevue.vue

common.css

* {
 margin: 0;
 padding: 0; }
.homeMain {
 text-align: center;
 margin-top: 100px; }
 .homeMain .routerName {
   color: #1eb89c;
   border: 1px solid #1eb89c;
   margin-top: 20px; }

/*# sourceMappingURL=common.css.map */

以上就是良许教程网为各位朋友分享的Linu系统相关内容。想要了解更多Linux相关知识记得关注公众号“良许Linux”,或扫描下方二维码进行关注,更多干货等着你 !

img
本文由 良许Linux教程网 发布,可自由转载、引用,但需署名作者且注明文章出处。如转载至微信公众号,请在文末添加作者公众号二维码。
良许

作者: 良许

良许,世界500强企业Linux开发工程师,公众号【良许Linux】的作者,全网拥有超30W粉丝。个人标签:创业者,CSDN学院讲师,副业达人,流量玩家,摄影爱好者。
上一篇
下一篇

发表评论

联系我们

联系我们

公众号:良许Linux

在线咨询: QQ交谈

邮箱: yychuyu@163.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

关注微博
返回顶部