动态引入组件并调用子组件方法

博客介绍了引用多个子组件并调用其方法的示例。给出了最底层index文件和汇总index文件的位置,说明通过引入汇总的index获取组件,若要调用子组件方法,可先输出$refs查看数据结构。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最底层index文件所在位置src\views\portal\portlet\intentionSection\index.js 

//index.js
export {default as intentionSection} from './intentionDataList';

 

所有底层index文件汇总的index文件所在位置src\views\portal\portlet\index.js 

//index.js
//导入模块
import {goalSection} from "./goalSection/index";
import {intentionSection} from "./intentionSection/index";
import {topicSection} from "./topicSection/index";
import {strateGoalCount} from "./strateGoalSection/index";

//导出模块
export {goalSection,intentionSection,topicSection,strateGoalCount};

 通过引入汇总的index得到每个组件

// 引入所有组件

import {intentionSection,topicSection, goalSection, strateGoalCount} from "@/views/portal/portlet";
export default {
  name: "contents",
  //注册组件
  components: {
    intentionSection,
    topicSection,
    goalSection,
    strateGoalCount
  },
}

 

//column.linkUrl是遍历的组件名称,:is是关键词
<template>
    <!-- keep-alive 失活的组件将会被缓存!-->
    <colComponent :ref="'ref'+column.linkUrl" :is="column.linkUrl" keep-alive></colComponent>

</template>

 需要调用子组件方法的话,先输出$refs,看数据结构,下面是我的一个例子

 console.log("输出的$refs对象"+$refs)
for (let i in this.$refs.refstrateGoalCount) {
          this.$refs.refstrateGoalCount[i].reloadDrawing();
    }

 

 *以上就是我引用多个子组件并且调用子组件方法的例子,希望能帮到像我一样的人

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值