Zia Yamin
Zia Yamin

Reputation: 1004

How to get id from dropdown in vue?

I am working with Vue and Laravel, I want to save data to the database, but I can not get the id of the selected category as I showed in the below picture, I can get other data like body and title. I don't know where is the problem. please help me.

enter image description here

This my code:

<template>
<v-container>
    <v-form @submit.prevent="create">
        <v-text-field
                v-model="form.title"
                label="title"
                type="text"
                required
        ></v-text-field>
        <v-select
        :items="categories"
        item-text="name"
        item-value="id"
        :v-model="form.category_id"
        label="Category"
        autocomplete>

        </v-select>
      
        <vue-simplemde v-model="form.body" />       

        <v-btn color="green" type="submit">
            Ceate
        </v-btn>

    </v-form>
</v-container>
</template>

<script>
import VueSimplemde from 'vue-simplemde'
export default {
    components: {
        VueSimplemde
    },
    data(){
        return {
            form:{
                title:null,
                category_id:null,
            },
            categories:{}
        }
    },
    created(){
        axios.get('/api/category')
        .then(res => this.categories = res.data.data)
    },
  methods:{
      create(){

      }
  }
}
</script>

<style scoped>
@import '~simplemde/dist/simplemde.min.css';
</style>

Upvotes: 0

Views: 183

Answers (1)

valentin
valentin

Reputation: 627

You have a colon before v-model

Replace :v-model with v-model

Upvotes: 1

Related Questions