Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

180
Vistas
How to set input value from method?

I create check-in system (Laravel + Vuetify), so i would like to ask: how to get userID from an object (API) en put them into input?

<template>
    <v-text-field
        v-model="debugItem.extra1_int"
        :counter="250"
        label="extra1_int"
        hint="userID"
        type="number"
        clearable>
    </v-text-field>
</template>

<script>
export default {
    data() {
        return {
            debugItem: {}, /* store new  debugItem */
            user: '',
        }
    },
    mounted() {
        this.getUser();
        this.debugItem.extra1_int = ***how to put here userID?***;
    },
    methods: {
    
        getUser() {
            axios.get('/user')
                .then(response => (this.user = response.data))
                .catch(error => console.log(error));
        },
        
        addDebugItem() { /* store new debugItem */
            this.axios
                .post('/api/debugs', this.debugItem)
                .then(response => (
                    this.$router.push({name: 'indexDebugs'})
                ))
                .catch(err => console.log(err))
                .finally(() => this.loading = false)
        }
    }
}
</script>

Method getUser() http://127.0.0.1:8000/user return json-object of logged user:

{
    "id": 119,
    "name": "Johan",
    "email": "Johan@mail.com",
    "email_verified_at": null,
    "is_active": 1,
    "created_at": "2022-05-09T14:24:48.000000Z",
    "updated_at": "2022-05-09T14:24:48.000000Z"
}

Thanks.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

<template>
    <v-text-field
        v-model="debugItem.userId"
        :counter="250"
        label="extra1_int"
        hint="userID"
        type="number"
        clearable>
    </v-text-field>
</template>

<script>
export default {
    data() {
        return {
            debugItem: {userId: null}, /* store new  debugItem */
            user: '',
        }
    },
    mounted() {
        this.getUser();
        this.debugItem.userId = this.user.id
    },
    methods: {
    
        getUser() {
            axios.get('/user')
                .then(response => (this.user = response.data))
                .catch(error => console.log(error));
        },
        
        addDebugItem() { /* store new debugItem */
            this.axios
                .post('/api/debugs', this.debugItem)
                .then(response => (
                    this.$router.push({name: 'indexDebugs'})
                ))
                .catch(err => console.log(err))
                .finally(() => this.loading = false)
        }
    }
}
</script>
about 4 years ago · Juan Pablo Isaza Denunciar

0

My suggestion, Instead of assigning value to this.debugItem.extra1_int in mounted() lifecycle hook. You can assign it in getUser() on success of axios call.

data() {
    return {
        debugItem: {},
        user: '',
    }
},
mounted() {
    this.getUser();
    this.debugItem.extra1_int = ***how to put here userID?***; ❌
},
methods: {
    getUser() {
        axios.get('/user')
            .then(response => {
                 this.user = response.data;
                 this.debugItem['extra1_int'] = this.user.id; ✅
             })
            .catch(error => console.log(error));
    }
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda