博客列表 >简单路由配置

简单路由配置

P粉036614676
P粉036614676原创
2022年09月16日 11:27:50410浏览

1、二级路由配置

  1. 1. 导入文件
  2. import Info from '../views/Info.vue';
  3. import Config from '../views/Config.vue';
  4. 2.配置路径
  5. {
  6. path:'/Course',
  7. name:'Course',
  8. component:Course,
  9. children:[
  10. {
  11. path:'/Course/Info',
  12. name:'Info',
  13. component:Info
  14. },
  15. {
  16. path:'/Course/Config',
  17. name:'Config',
  18. component:Config
  19. }
  20. ]
  21. },
  22. 3.路由配置
  23. <router-link to="/Info"> Info </router-link>
  24. <router-link to="/Config">Config </router-link>
  25. <router-view></router-view>

2、路由守卫

3、组合API

  1. <template>
  2. <div>
  3. <h1>{{name}}</h1>
  4. <button @click="fun">点击增加</button>
  5. <p v-text="data.value"></p>
  6. <p>asjfdh</p>
  7. </div>
  8. </template>
  9. <script>
  10. import { reactive,ref ,watch} from 'vue';
  11. export default{
  12. setup(){
  13. const name='yk';
  14. let data = reactive({
  15. value:0
  16. });
  17. const dd = ref('ass');
  18. function fun()
  19. {
  20. data.value++;
  21. console.log(dd.value);
  22. }
  23. watch(dd,()=>{
  24. console.log(dd.value);
  25. })
  26. return {
  27. name,
  28. fun,
  29. data
  30. }
  31. }
  32. }
  33. </script>
  34. <!-- <script setup>
  35. import { numberLiteralTypeAnnotation } from '@babel/types';
  36. import { reactive } from 'vue';
  37. const name='yk';
  38. let num = 0;
  39. let data = reactive({
  40. value:num
  41. })
  42. let fun = ()=>{
  43. data.value++;
  44. }
  45. </script> -->
  46. <!-- <script>
  47. import { reactive,ref } from 'vue';
  48. export default{
  49. setup(){
  50. const name='yk';
  51. let data = reactive({
  52. value:0
  53. });
  54. const dd = ref('asd');
  55. function fun()
  56. {
  57. data.value++;
  58. console.log(dd.value);
  59. }
  60. return {
  61. name,
  62. fun,
  63. data
  64. }
  65. }
  66. }
  67. </script> -->
声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议