vuerouter-2.路由跳转

1.单独的设置路由的index.js

-------------------------------------------------------------------------------------

import Vue from 'vue'
import VueRouter from 'vue-router'
//@表示寻找根目录
import HelloWorld from '@/components/HelloWorld'
import learn from '@/components/learn'
Vue.use(VueRouter)
//创建路由
export default new VueRouter({
routes:[
{
path:"/h",
name:"HelloWorld", //可以作为跳转使用
component:HelloWorld
},
{
path:"/learn",
name:"learn",
component:learn
}
]
})

--------------------------------------------------------------------------------------------------------------------

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'
Vue.config.productionTip = false

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

实例---------------------------------------------------------------------------------------------------------------

<template>
<div id="app">
<img src="./assets/logo.png">
<ul>
<router-link to="/h" tag="li">HelloWorld</router-link>
<router-link to="/learn" tag="li">learn</router-link>
</ul>
<router-view />
</div>
</template>

<script>
export default {
name: 'App',
components: {

}
}
</script>

<style>
#app {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}

ul li {
text-align: center;
display: inline-block;
text-decoration: underline;
cursor: pointer;
color: blue;
}

ul li+li {
margin-left: 20px;
}
</style>

posted @ 2019-08-11 18:27  星雨,恒奋斗,过客  阅读(178)  评论(0编辑  收藏  举报