当前位置: 首页 > news >正文

Java学习笔记之:Vue中路由的基本使用

一、安装 Vue Router

  1. 使用 npm 安装:
    • 在项目根目录下运行命令npm install vue-router@4 --save

二、创建路由配置文件

  1. 首先创建3个vue文件,分别命名为:one.vue,two.vue,ElpView.vue,要实现的效果:在Vue.vue中使用ElpView组件然后在ElpView.vue使用one,two组件,最后在浏览器显示one,two,点击one跳转到one.vue,点击two跳转到two.vue。one.vue和two.vue文件里面内容分别如下:

    one.vue:

    <template><p>这是one</p>
    </template>
    

    tow.vue:

    <template><p>这是two</p>
    </template>
    
  2. 创建一个router.js文件,在里面配置相关内容:

    import { createRouter, createWebHistory } from 'vue-router'import One from '@/components/one.vue'
    import Two from '@/components/two.vue'
    import ElpView from '@/components/ElpView.vue'const routes = [{path: '/one',name: 'wo',component: One},{path: '/two',name: 'ai',component: Two},{path: '/',name: 'ni',component: ElpView}
    ]const router = createRouter({history: createWebHistory(),routes
    })export default router
  3. 在ElpView.vue中使用router-link标签配置:

    <template><div><router-link to="/one">one</router-link><br><router-link to="/two">two</router-link></div>
    </template><script>
    import one from './one.vue';
    import two from './two.vue';
    export default{components:{one,two,}
    }
    </script>
    <style></style>
    
  4. 在根组件Vue.vue下使用router-view标签配置:

    <template><router-link to='/elpview'></router-link>
    <router-view></router-view></template><script lang="js" >
    import ElpView from './components/ElpView.vue';
    import one from './components/one.vue';
    import two from './components/two.vue';
    export default {components: {ElpView ,one,two}
    }
    </script>
    

通过以上配置,就可以实现在vue工程中,点击不同的按钮跳转到不同的页面。

http://www.xdnf.cn/news/1006561.html

相关文章:

  • 日语学习-日语知识点小记-构建基础-JLPT-N4阶段(34):ようですそうですばかりのに
  • 由于现在ui设计软件百花齐放,用传统的photoshop设计页面的方式正被摒弃
  • YOLOv2 技术详解:目标检测的又一次飞跃
  • 力扣100- 环形链表
  • vue-property-decorator实践(一)
  • 在 pgvector 中指定相似度搜索方法
  • 能提升30%!Infortrend普安存储自动分层增强版赋能文件共享与医疗影像
  • 华为OD机考-英文输入法-逻辑分析(JAVA 2025B卷)
  • 从 CAN FD 到 SD NAND(SLC)存储:S32K146 T-Box 如何驱动车载数据架构革新?
  • LeetCode 1143. 最长公共子序列 | 动态规划详解
  • 无人机遥控器低延迟高刷新技术解析
  • C# .NET Core Source Generator(C# .NET Core 源生成器)
  • md文件转word文档
  • 单元测试基本步骤
  • Spring MVC 常用请求处理注解总结
  • llm agent
  • OpenCV CUDA模块图像变形------对图像进行任意形式的重映射(Remapping)操作函数remap()
  • Spring Boot3批式访问Dify聊天助手接口
  • Vue 中 this.$emit(‘mount‘) 的妙用
  • 如何在 Discourse AI 中设置 Gemini API
  • 多串口卡使用
  • 软件测试BUG
  • 【小工具】-Doxygen01
  • slam--非线性优化
  • BEV和OCC学习-8:mmdet3d 3D分割demo测试
  • 如何利用单细胞转录组进行细胞图谱和疾病机制研究?
  • 爬虫实践:TOP250电影数据
  • 从数学到代码:一文详解埃拉托色尼筛法(埃式筛)
  • 阳台光伏防逆流电表革新者:安科瑞ADL200N-CT/D16-WF
  • ref 应用于对象类型的一个案例