gpt4 book ai didi

vue.js - 传入一个有引用值(value)的slot?

转载 作者:行者123 更新时间:2023-12-05 06:35:49 25 4
gpt4 key购买 nike

在我的组件中,我有这个作用域插槽:

<slot name="test">
<input ref="inputTest">
</slot>

在 parent 中我这样做:

<div slot="test">
<input ref="inputTest">
</div>

但是当我稍后尝试在我的组件中访问 ref 时:

console.log(this.$refs.inputTest);

我不确定。

如何传入一个有引用的槽?

最佳答案

您不能从父组件到子组件访问 refs

您可以使用 scoped slot在它们之间传递数据。

<!-- pass ref as props -->
<slot name="test" :ref="inputTest">
<input ref="inputTest">
</slot>


<!-- receive ref props -->
<template slot-scope="ref">
<!-- bind ref to $refs -->
<input ref="ref">
</div>

这显然会令人困惑。因此,我建议为 props 使用任何其他合适的名称而不是 ref。

关于vue.js - 传入一个有引用值(value)的slot?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49492389/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com