[Vuejs]-How to display different dropdown options in a component depending on a given value

0👍

Your Groceries component should be like :

<template lang="html">
  <div class="">
    <select class="Groceries" name="">
      <option v-for="val in values" v-bind:value="val">{{ val }}</option>
    </select>
    </div>
</template>

<script>
  export default {
    name: 'Groceries',
    props: ["values"],
    data() {
      return {

      }
    }
  }
</script>

and call it in a parent one a follow :

<template>
  <div class="">
      <Groceries :values="values.fruit"/>
      <Groceries :values="values.veg"/>
    </div>
</template>

<script>
  import Groceries from './Groceries.vue'
  export default {
    name: 'myapp',
    data() {
      return {
        values: {
          fruit: ['apple', 'orange', 'pear'],
          veg: ['carrot', 'pea', 'sprout']
        },
      }
    },
    components: {
      Groceries
    }
  }
</script>

Leave a comment