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

机关单位网站安全建设怎么联系地推公司

机关单位网站安全建设,怎么联系地推公司,东莞工程,wordpress自带注册在 Vue 3 中,子组件若要获取父组件的 name,且父组件不做额外操作,可以借助 getCurrentInstance 来实现。getCurrentInstance 方法能获取当前组件实例,进而访问其父组件实例及其属性。 示例代码 父组件(ParentComponent…

在 Vue 3 中,子组件若要获取父组件的 name,且父组件不做额外操作,可以借助 getCurrentInstance 来实现。getCurrentInstance 方法能获取当前组件实例,进而访问其父组件实例及其属性。
示例代码
父组件(ParentComponent.vue)

<template><div><h1>这是父组件</h1><ChildComponent /></div>
</template><script setup>
import { defineComponent } from 'vue';
import ChildComponent from './ChildComponent.vue';// 定义父组件名称
defineComponent({name: 'ParentComponent'
});
</script>

子组件(ChildComponent.vue)

<template><div><h2>这是子组件</h2><p>父组件的名称是: {{ parentName }}</p></div>
</template><script setup>
import { getCurrentInstance } from 'vue';// 获取当前组件实例
const instance = getCurrentInstance();
// 获取父组件的 name
const parentName = instance?.parent?.type.__name;
</script>

代码解释
父组件:
运用 defineComponent 定义父组件,并且指定 name 为 ParentComponent。
在模板里引入并使用子组件 ChildComponent。
子组件:
借助 getCurrentInstance 获取当前组件实例。
通过 instance?.parent 访问父组件实例。
利用 instance?.parent?.type.__name 获取父组件的 name。
把获取到的父组件 name 展示在模板中。
注意事项
getCurrentInstance 仅能在 setup 函数或者 <script setup> 中使用。
由于 getCurrentInstance 可能返回 null,所以在访问父组件实例及其属性时,要使用可选链操作符 ?. 来避免出现空指针错误。
----来自豆包

http://www.dtcms.com/wzjs/370227.html

相关文章:

  • protenus代做网站佛山网络排名优化
  • 北京有哪些网站建设公司好seo作弊
  • 在哪请人做网站zac seo博客
  • 雄安网站建设机构优化 保证排名
  • wordpress移动端 菜单百度网站排名seo
  • 网站建设客户需求分析表网站制作模板
  • wdcp网站无法访问小程序开发教程
  • 网站的竞争对手广州新闻24小时爆料热线
  • 安徽网站建设有限公司哈尔滨seo网站管理
  • wordpress首页文章显示图片seo搜索引擎
  • wordpress 育儿主题成都seo优化公司排名
  • 南充公司做网站免费注册个人网站不花钱
  • 汕头网站关键排名seo排名优化培训价格
  • 做外贸需要注册哪些b2b网站免费人脉推广
  • 在线网站搭建系统网店推广方法
  • 网页设计网站页面代码seo接单平台有哪些
  • 小程序推广话术案例seo搜索引擎优化工具
  • 好的龙岗网站建设盘多多网盘资源库
  • 响应式网站开发哪个好百度云网盘入口
  • 久久网站建设游戏推广文案
  • 政府类型网站建设方案怎么做互联网推广
  • 网站建设试题卷网页免费制作网站
  • 设计学习网站抖音seo招商
  • b2b电子商务平台网站有哪些网络营销推广策划书
  • 大良商城网站建设网站seo优化技巧
  • wordpress 二维码插件下载网站seo推广seo教程
  • 助君网络科技深圳seo云哥
  • 期末成绩管理网站开发背景免费seo网站优化工具
  • 网站网页优化技巧中国公关公司前十名
  • 厦门知名网站建设chatgpt中文在线