简体   繁体   English

Vuejs-使用模板将父组件属性传递给子元素

[英]Vuejs - Passing parent component props to child element with the template

The problem I'm trying to solve is I want the child component to react when a v-expansion panel is expanded/contracted. 我要解决的问题是我希望子组件在v展开面板展开/收缩时做出反应。

Normally this would be trivial, however, I'm attempting to pass a value from a prop within a vuetify component to component via a scoped slot. 通常这是微不足道的,但是,我试图通过范围化的插槽将值从vuetify组件内的prop传递到组件。 Because I'm rendering the child components within a loop, I can't just use Data to bind the prop. 因为我是在循环中渲染子组件,所以不能仅使用Data绑定道具。

  <v-expansion-panel expand>    
   <v-expansion-panel-content 
     v-for="item in this.items"
     :key="item.key">
     <div slot="header">
       content
     </div>          
   <slot :items="item.children"></slot>
  </v-expansion-panel-content>
 </v-expansion-panel>  

The v-expansion-panel-content has a prop called value. v-expansion-panel-content具有一个称为值的属性。 I need to bind that prop to the slot. 我需要将该道具绑定到插槽。 Ideally, I'd like to achieve something like this: 理想情况下,我想实现以下目标:

<slot :items="item.children" :panelValue="value"></slot>

Any ideas would be greatly appreciated. 任何想法将不胜感激。

I've solved this, but in a less than ideal way. 我已经解决了这个问题,但是方法不太理想。

<v-expansion-panel expand>    
  <v-expansion-panel-content
    v-for="item in this.items"
    :key="item.key"
    v-model="item.isOpen">
    <div slot="header">
      content
    </div>       
  <slot :items="item.children" :isVisible="item.isOpen"></slot>
</v-expansion-panel-content>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何确保父组件将填充的 props 传递给 VueJS 中的子组件 - How to ensure that parent is passing populated props to a child component in VueJS 更改子组件内部 props 创建的数组元素也会影响父组件的 props | Vuejs 3 - Changing the element of an array created from the props inside the child component also affect the parent component's props | Vuejs 3 VueJS-道具不会通过父项的更改在子项中更新 - VueJS - Props are not updated in child component by changes in parent Vue父组件道具未传递给子组件 - Vue parent component props are not passing to child component React父级组件道具未传递给子级组件 - React parent component props are not passing to child component 父组件未将 Firebase 道具传递给子组件 - Parent Component not Passing Firebase props to Child Component 在VueJS中将父函数传递给子组件 - Passing Parent Function to Child Component in VueJS 使用prop将子组件数据传递给父组件 - Passing child component data to parent using props Vuejs将道具从父组件传递到子组件不起作用 - Vuejs passing props to from parents component to child component not working 将子组件中的文本字段链接到 VueJS 中父组件的道具 - Linking a text field in a child component to a parent component's props in VueJS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM