0

I am new in Vue.js. I want to update data from ajax data.

<template>
  <span class="label_cont">This is to certify that</span> {{ name }}
</template>

I want to {{ name }} variable from ajax data.
Here is my js code

export default{
  created(){
    const url = 'app/result.php';
    this.$http.get(url).then(response => {
      this.resp = response.body;
    });
  },
  data(){  
    return {
     resp:[],
     name: resp.name,
   }
  }
}

In my ajax name property is in this.resp.name

Update:

Here is my ajax response data format

{
  "name": "X",
  "class": "Y",
  "roll": "Z"
}
2
  • what data you have response.body? show us data format Commented May 25, 2017 at 5:04
  • I have update the data format Commented May 25, 2017 at 5:09

1 Answer 1

2

Add the extra line to your callback below.

this.$http.get(url).then(response => {
  this.resp = response.body;
  this.name = response.name
});

In your data just initialize it to null.

data(){  
  return {
    resp:[],
    name: null,
  }
}

Alternatively you could just use

{{resp.name}}

in your template.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.