MICUU
微资讯
声卡
创新2024全套教程
5.1声卡全套
创新声卡驱动
板载声卡调试全套教程
Sam机架安装
Sam机架
音效助手
专题
文档
技术文档汇总
站内文档
更多
软件
更新日志
关于
装机必备
Gramos模板
光年后台模板
Betube模板
美图
友情链接
站内导航
关于
搜索
退出登录
登录
原创
vue新项目搭建vue-router 在项目中的使用
2020-05-15
28.63w热度
一、下载vue-router npm install vue-router --save 二、编码 1、在项目中新建文件夹 router/index.js ``` import Vue from 'vue' import VueRouter from 'vue-router' Vue.use(VueRouter) import page from '@/pages/index/index.vue' import login from '@/pages/login/index.vue' export default new VueRouter({ routes: [ { path: '/page', name: 'page', component: page, meta: { title: '首页' } } ,{ path: '/login', name: 'login', component: login, meta: { title: '登录' } } ] ,mode: "history" }) ``` 2、在main.js中全局使用router ``` import Vue from 'vue' import App from './App.vue' import Vant from 'vant'; import router from './router' //引入路由 import 'vant/lib/index.css'; Vue.use(Vant); //修改路由标题 router.beforeEach((to, from, next) => { /* 路由发生变化修改页面title */ if (to.meta.title) { document.title = to.meta.title; } next(); }) new Vue({ render: h => h(App), router //引入路由 }).$mount('#app') ``` 2)在App.vue引入FooterGuide.vue组件 和 router-view 区域 <router-view></router-view> 重要 ``` <template> <div id="app"> <router-view></router-view> <Index /> </div> </template> <script> import Index from './pages/index/index.vue' export default { name: 'App', components: { Index } } </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> ``` 4页面跳转 ``` <template> <div> <button @click="go" type="default">默认按钮</button> </div> </template> <script> export default { name: 'index', data () { return { msg: '哈哈' } }, methods:{ go(){ this.$router.push({path:'/login'}); //this.$router.replace({path:'/login'}) } } } </script> ```
注:原创不易,转载请注明出处(
https://micuu.com/new/494.html
),本站所有资源来源于网络收集,如有侵权请联系QQ245557979进行清除。
最后修改与 2022-02-19
上一篇:
tp5,tp6关联查询haswhere使用闭包传参,多模型关联查询
下一篇:
vue input添加回车触发
留言反馈
请先登录
问题反馈渠道,如有软件无法下载或者其他问题可反馈。【由于某种原因,目前留言不展示】
用户需要登录后才能留言反馈
立即留言
珍藏视频
10分钟高效燃脂
30天高效瘦脸操
5分钟缓解颈椎操
友人
微博
全民K歌
唱吧
今日头条
悠悠网
科技小锅盖
彼岸桌面
阮一峰
laravel社区
V2ex
掘金
更多>