首页 > 其他 > 详细

vue 路由 vue-router

时间:2021-02-13 08:38:08      阅读:31      评论:0      收藏:0      [点我收藏+]

views文件夹下:

about.vue

<template>
    <div>about</div>
</template>

<script>
</script>

<style>
</style>

 

home.vue

<template>
    <div>home</div>
</template>

<script>
</script>

<style>
</style>

router文件夹下:

index.js

import Vue from "vue"
import VueRouter from "vue-router"
import about from "../views/about.vue"
import home from "../views/home.vue"
Vue.use(VueRouter)
export default new VueRouter({
    routes:[
        {
            path:"/about",
            component:about
            
        },
        {
            path:"/home",
            component:home
        },
        {
            path:"/",
            redirect:"/about"
        }
    ]
})

main.js

import Vue from vue
import ElementUI from element-ui
import element-ui/lib/theme-chalk/index.css
import App from ./App.vue
import router from ./router/index.js 

Vue.use(ElementUI)

 new Vue({
  el: #app,
  render: h => h(App),
    router
}) 

App.vue:

<template>
  <div id="app">
        <div>
            <router-link to="/about" class="active">about</router-link>
            <router-link to="/home">home</router-link>
        </div>
        <div>
            <router-view></router-view>
        </div>
    <div>
    </div>
  </div>
</template>

<script>
export default {
     data() {
    },
        created:function(){
        this.$alert("111")
        },
  methods: {
  }
}
</script>

<style>
</style>

index.html加个样式:

    .router-link-active {color: red;}

技术分享图片

 

vue 路由 vue-router

原文:https://www.cnblogs.com/fengwenzhee/p/14399529.html

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