uni-app 父组件调用子组件方法

父组件:
<view v-else><itemNav :indexddd="itemObj" ref="childNav"></itemNav></view>
uni.$on('ajaxApiRequest222', this.$refs.childNav.sjsd(name));
子组件:	
props: {
	     indexddd: '',
	     required: true
	   },
 sjsd: function(name) {
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
uni-app中,可以使用slot插槽来实现组件控制组件显示指定内容。具体步骤如下: 1. 在组件中定义一个或多个slot插槽 ```html <template> <div> <slot name="content"></slot> <slot name="other"></slot> </div> </template> ``` 2. 在组件调用组件,并在需要的地方插入内容 ```html <template> <div> <child> <template v-slot:content> <p>这是内容</p> </template> <template v-slot:other> <p>这是其他内容</p> </template> </child> </div> </template> ``` 在上面的例中,组件调用组件,并通过slot插槽向组件传递了两个内容,一个是content插槽中的内容,一个是other插槽中的内容。在组件中,使用slot插槽来显示这些内容。 如果需要在组件中控制组件显示指定内容,可以使用v-if指令来控制插槽中的内容是否显示。例如,可以在组件中定义一个变量showContent,然后在content插槽中使用v-if指令来控制显示: ```html <template> <div> <button @click="showContent = !showContent">切换显示内容</button> <child> <template v-slot:content> <p v-if="showContent">这是内容</p> <p v-else>暂无内容</p> </template> <template v-slot:other> <p>这是其他内容</p> </template> </child> </div> </template> <script> export default { data() { return { showContent: true } } } </script> ``` 在上面的例中,定义了一个按钮,点击按钮可以切换显示内容。在content插槽中,使用v-if指令来判断showContent变量的值,如果为true则显示内容,否则显示暂无内容。通过这种方式,就可以在组件中控制组件显示指定内容。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

冉然

你的鼓励对我很重要

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值