【问题标题】:VUETIFY - How to pass slot to nested select componentVUETIFY - 如何将插槽传递给嵌套选择组件
【发布时间】:2019-12-05 00:17:41
【问题描述】:

我正在使用vuetify 的最新版本并试图弄清楚如何使插槽工作。关于 select 的文档可以在here找到。

VSelectWithValidation

<v-select v-model="innerValue" :error-messages="errors" v-bind="$attrs" v-on="$listeners">
  <template slot="selection" slot-scope="data">
      {{ data.item.name }}
  </template>
   <template slot="item" slot-scope="data">
      {{ data.item.name }} - {{ data.item.description }}
  </template>
</v-select>

测试组件

<VSelectWithValidation
    rules="required"
    :items="items"
    v-model="select"
    label="Select">
    // I WOULD LIKE SLOTS TO BE AT THIS LEVEL
</VSelectWithValidation>

基本上,我希望自定义插槽,因此我需要将它们移出VSelectWithValidation 组件以在TestComponent 上设置

我尝试了不同的变体,但没有成功。

https://codesandbox.io/s/veevalidate-components-vuetify-u11fd

【问题讨论】:

    标签: vue.js vuetify.js v-slot


    【解决方案1】:

    VSelectWithValidation

    您需要在模板插槽项中创建插槽并将范围数据绑定到能够从其他组件中使用..

    <template slot="item" slot-scope="data">
       <slot name="item" v-bind="data"></slot>
    </template>
    

    测试组件

    您可以通过编写 v-slot:YourSlotName="hereIsBindData"

    访问该插槽
    <template v-slot:item="data">
        {{ data.item.name }} // you can code here whatever you like
    </template>
    

    【讨论】:

    • 有什么办法让它成为可选的吗?现在,我没有通过插槽的每个选择都被破坏了。
    • 如何添加名为 isSlot(boolean) 的新道具来检查当前是否选择使用插槽 v-if="isSlot" ...
    • @LéoCoco,v-if="$slots.item" 检查名为“item”的插槽怎么样?
    猜你喜欢
    • 2019-04-25
    • 2020-03-12
    • 2018-09-14
    • 2020-12-01
    • 2020-04-23
    • 2017-12-06
    • 1970-01-01
    • 2018-07-28
    • 1970-01-01
    相关资源
    最近更新 更多