登录  /  注册
博主信息
博文 49
粉丝 0
评论 3
访问量 30959
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
url的传值,2级路由的配置,重定向,导航守卫,组合API
P粉479712293
原创
571人浏览过

题目1:url的传值

图1:

题目2:2级路由的配置

1.index.js文件:

  1. import { createRouter, createWebHistory } from 'vue-router'
  2. import Index from '../views/Index.vue'
  3. import Course from '../views/Course.vue'
  4. import List from '../views/List.vue'
  5. import User from '../views/User.vue'
  6. import UserConfig from '../views/User/config.vue'
  7. import UserInfo from '../views/User/info.vue'
  8. const routes = [
  9. {
  10. path: '/',
  11. name: 'home',
  12. component: Index
  13. },
  14. {
  15. path: '/course',
  16. name: 'course',
  17. component: Course
  18. },
  19. {
  20. path: '/list',
  21. name: 'list',
  22. component: List
  23. },
  24. {
  25. path: '/user',
  26. name: 'user',
  27. component: User,
  28. children:[
  29. {
  30. // 路由地址配置,就是浏览器上的url
  31. path:'userconfig',
  32. // 页面的名称,自定义,但不要重复
  33. name:'userconfig',
  34. // 这个是页面文件的路径
  35. component:UserConfig
  36. },
  37. {
  38. path:'userinfo',
  39. name:'userinfo',
  40. component:UserInfo
  41. }
  42. ]
  43. }
  44. ]
  45. const router = createRouter({
  46. history: createWebHistory(process.env.BASE_URL),
  47. routes
  48. })
  49. export default router

2.config.vue文件:

  1. <template>
  2. <div style="color:red">这是用户配置页面</div>
  3. </template>

3.info.vue文件:

  1. <template>
  2. <div style="color:red">这是用户信息页面</div>
  3. </template>

4.App.vue文件:

  1. <template>
  2. <nav>
  3. <router-link to="/">首页</router-link> |
  4. <router-link to="/course">课程</router-link> |
  5. <router-link to="/list">列表</router-link> |
  6. <router-link to="/user?id=100">用户中心</router-link>
  7. </nav>
  8. <router-view/>
  9. </template>
  10. <style lang="scss">
  11. #app {
  12. font-family: Avenir, Helvetica, Arial, sans-serif;
  13. -webkit-font-smoothing: antialiased;
  14. -moz-osx-font-smoothing: grayscale;
  15. text-align: center;
  16. color: #2c3e50;
  17. }
  18. nav {
  19. padding: 15px;
  20. a {
  21. font-weight: bold;
  22. color: #2c3e50;
  23. &.router-link-exact-active {
  24. color: #42b983;
  25. }
  26. }
  27. }
  28. </style>

5.浏览器效果图:

图1:

图2:

图3:

图4:

题目3:重定向

图1:

题目4:导航守卫

图1:示例1

图2:示例2

题目5:组合API

图1:setup方法的数据显示

图2:setup监听事件中方法

图3:setup的reactive与ref参数

图4:setup的watch侦听模块

图5:setup的watch侦听模块倒计时

图6:引入组件setup的传值

批改老师:PHPzPHPz

批改状态:合格

老师批语:
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
作者最新博文
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学