Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

176
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!