[Vuejs]-Set v-model value within a slot in Vuejs

2👍

EDIT – modified the code to handle variable number of inputs

In the child component

<template>
    <div class="container">
        <slot :data="slotData" />
    </div>
</template>
<script>
  export default
  {
    data()
    {
      return {
        slotData: ['1', '2', '3']
      };
    }
  }
</script>

In the parent component

<template>
    <my-component>
      <template slot-scope="props">
        <input v-for="item in props.data" type="text" v-model="item">
      </template>
    </my-component>
</template>

Leave a comment