Blogger Information
Blog 49
fans 0
comment 3
visits 23000
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
url的传值,2级路由的配置,重定向,导航守卫,组合API
P粉479712293
Original
426 people have browsed it

题目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的传值

Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post