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

145
Views
Vue.js 2 Set all reactive properties from API call

I have a vue component with some properties eg.

import { getAPI } from "@/axios-api";
import { mapGetters, mapActions } from "vuex";
export default {
  name: "edit-profile-form",
  data() {
    return {
      first_name: "",
      last_name: "",
...

I also have an API call that will get these properties, which have exactly the same name eg.

{
   "first_name": "Jon",
   "last_name": "Doe"
}

Is there a way I can update both properties simultaneously? instead of doing

axios.get('/url/').then(res => {
  this.first_name = res.first_name;
  this.first_name = res.first_name;
});

Thanks

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

A quick way to copy those fields into your data is to use Object.assign():

axios.get('/url/').then(res => {
  Object.assign(this.$data, res.data)
});

demo

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!