首页 > 其他 > 详细

vuerouter-2.路由跳转

时间:2019-08-11 18:50:24      阅读:88      评论:0      收藏:0      [点我收藏+]

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>

vuerouter-2.路由跳转

原文:https://www.cnblogs.com/xiao-peng-ji/p/11335963.html

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