简体   繁体   English

从slot-scope获取数据

[英]Getting data from slot-scope

<template slot="item-template" slot-scope="{ item }">
<div class="typeahead-value">{{ item.partnerName }} </div>
<div class="typeahead-info">
<b>Eori:</b> {{ item.partnerEori }} <br>
<b>Tara:</b> {{ item.countryName }}
</div>
</template>

Is there any way, i can get the value item.partnerName so i can put that value in a validation?Or any value 有什么办法可以获取值item.partnerName以便将该值放入验证中?或任何值

It is not clear why you can't access item but within your slot you should be able to access item . 目前尚不清楚为什么您无法访问item但您应该可以在插槽内访问item item is a property which is accessible via destructuring of the slotProps item是可以通过slotProps来访问的slotProps

<template v-slot:item-template="{ item }">
  <p>You can access item here</p>
</template>

To pass in item as a variable, you can add it to your slot component 要将item作为变量传递,您可以将其添加到广告位组件中

  <slot
    name="item-template"
    :item="item"
  ></slot>

Regarding to your questions in the comments 关于您在评论中的问题

This is just a basic example showing how to create a slot component and consume it. 这只是一个基本示例,显示了如何创建和使用插槽组件。

This example slot component InputItem takes in a input field (slot) and emits an event when the value got updated 示例插槽组件InputItem接受一个输入字段(插槽),并在值更新后发出一个事件

<template>
  <v-container>
    <slot name="field" :inputHandler="update"></slot>
  </v-container>
</template>

<script>
export default {
  props: {
    currentValue: {
      required: true
    }
  },
  methods: {
    update: function(newValue) {
      this.$emit("updated", newValue);
    }
  }
};
</script>

Your consuming component would be 您的消耗组件是

<template>
  <v-container>
    <InputItem :currentValue="value" @updated="onUpdate">
      <template v-slot:field="{ inputHandler }">
        <v-text-field 
          :value="value" 
          @input="inputHandler"
        ></v-text-field>
      </template>
    </InputItem>
  </v-container>
</template>

<script>
import InputItem from "../../components/InputItem";

export default {
  components: {
    InputItem
  },
  data: function() {
    return {
      value: "not empty"
    };
  },
  methods: {
    onUpdate: function(newValue) {
      this.value = newValue;
    }
  }
};
</script>

The provided example HTML code uses Vuetify elements but I hope this is ok. 所提供的示例HTML代码使用Vuetify元素,但我希望可以。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM