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

vue3获取defineOptions的值;vue3获取组件实例;vue3页面获取defineOptions的name

文章目录

    • 1.当前vue页面获取defineOptions的name
    • 2.通过绝对路径获取defineOptions的name
    • 3.需求设计

1.当前vue页面获取defineOptions的name

通过获取组件实例的方式获取
在这里插入图片描述

import { onMounted,getCurrentInstance } from "vue"defineOptions({name: "RealTimeAlarm"
})
const instance = getCurrentInstance() // 获取组件实例onMounted(() => {console.log(instance, instance?.type?.name)
})

2.通过绝对路径获取defineOptions的name

// @/utils/filter.js// 注册一个通过路径获取name的方法
export const getComponentName = async (component) => {try {const module = await componentconst componentName = module.default.name;console.log('vue页的Name:', componentName);return componentName;} catch (error) {console.error('Error loading component:', error);return null;}
}
import { getComponentName } from "@/utils/filter.js";getComponentName(import(`@/views/monitoringManagement/alarmMonitoring/realTimeAlarm/index.vue`)).then(componentNameStr => {console.log('当前vue页面的name,注意不是路由name', componentNameStr)
}).catch(console.error);

3.需求设计

当时我的vue路由是动态路由,所以我就将动态路由的name和vue页面的name通过脚本设置一致;后续我就可以通过
–知道要跳转的文件的绝对路径
–找到对应name(因为vue实例name和vue路由name一致)
–也就可以可以通过跳转到正确的路由去

router.push({ name: componentNameStr, query: { searchData: JSON.stringify(query) } })

http://www.mrgr.cn/news/98721.html

相关文章:

  • 分布式热点网络
  • AI大模型学习九:‌Sealos cloud+k8s云操作系统私有化一键安装脚本部署完美教程
  • 集群搭建Weblogic服务器!
  • 《Against The Achilles’ Heel: A Survey on Red Teaming for Generative Models》全文阅读
  • 红宝书第四十七讲:Node.js服务器框架解析:Express vs Koa 完全指南
  • 前端基础之《Vue(5)—组件基础(1)》
  • Kubernetes(K8S)内部功能总结
  • 猫咪如厕检测与分类识别系统系列【六】分类模型训练+混合检测分类+未知目标自动更新
  • 【Vue】从 MVC 到 MVVM:前端架构演变与 Vue 的实践之路
  • shell 编程之正则表达式与文本处理器
  • centos7停服yum更新kernel失败解决办法
  • C++中变量、函数存储、包括虚函数多态实现机制说明
  • Deno 统一 Node 和 npm,既是 JS 运行时,又是包管理器
  • chili3d调试笔记2+添加web ui按钮
  • 基础学习:(6)nanoGPT
  • 单片机基础知识-STM32
  • vue3.2 + element-plus 实现跟随input输入框的弹框,弹框里可以分组或tab形式显示选项
  • YOLOV8 OBB 海思3516训练流程
  • 十八、TCP多线程、多进程并发服务器
  • Tomcat与Servlet