时间:2021-07-01 10:21:17 帮助过:5人阅读
1.首先npm中是否有vue-router
一般在vue-cli的时候就已经下载好了依赖包了
2.使用vue的话正常的需要涉及这几个文件
demo/src/router/index.js
demo/src/app.vue
<template>
<p id="app">
<img src="./assets/logo.png">
<p>
<router-link to="/home">home</router-link>//跳转首页
<router-link to="/test">test</router-link>//跳转新页面
</p>
<router-view></router-view>//页面渲染放置的部分
</p>
</template>
<script>
export default {
name: 'app'
}
</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;
}
</style>demo/src/main.js
两个页面的组件

这样的话,基本的路由设置就好了,可以按照正常的npm run dev运行这个项目了
另外还有嵌套 自定义多种路由
具体的路由内容可以查看:https://router.vuejs.org/zh-cn/installation.html
相关推荐:
使用路由延迟加载Angular模块实例详解
angular中使用路由和$location切换视图_AngularJS
Vue-Router2实现路由功能实例讲解
以上就是在vue-cli中使用路由的方法的详细内容,更多请关注Gxl网其它相关文章!