您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

在vue-cli中使用路由的方法

2024/3/29 23:51:47发布14次查看
本文主要和大家介绍在vue-cli中使用路由的方法,给大家做个参考,希望能帮助大家正确在vue-cli中使用路由。
1.首先npm中是否有vue-router
一般在vue-cli的时候就已经下载好了依赖包了
2.使用vue的话正常的需要涉及这几个文件
demo/src/router/index.js
import vue from 'vue' import router from 'vue-router' import hello from '../components/hello'//首页 import test from '../components/test'//需要跳转的页面 给组件重新命名 vue.use(router) export default new router({ routes: [ {//首页 path: '/', name: 'hello', component: hello }, {//需要跳转的页面 path:'/test', name:'test', component:test//组件名字 } ] })
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
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, template: '<app/>', components: { app } }).$mount('#app')//实例挂载到元素中
两个页面的组件
这样的话,基本的路由设置就好了,可以按照正常的npm run dev运行这个项目了
另外还有嵌套 自定义多种路由
具体的路由内容可以查看:https://router.vuejs.org/zh-cn/installation.html
相关推荐:
使用路由延迟加载angular模块实例详解
angular中使用路由和$location切换视图_angularjs
vue-router2实现路由功能实例讲解
以上就是在vue-cli中使用路由的方法的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product