[英]Vue.js update ajax data in data property variable
I am new in Vue.js. 我是Vue.js的新手。 I want to update data from ajax data. 我想从ajax数据更新数据。
<template>
<span class="label_cont">This is to certify that</span> {{ name }}
</template>
I want to {{ name }}
variable from ajax data. 我想从ajax数据中{{ name }}
变量。
Here is my js code 这是我的js代码
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
在我的ajax name
属性位于this.resp.name
Update: 更新:
Here is my ajax response data format 这是我的ajax响应数据格式
{
"name": "X",
"class": "Y",
"roll": "Z"
}
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. 在您的数据中,只需将其初始化为null。
data(){
return {
resp:[],
name: null,
}
}
Alternatively you could just use 或者,您可以只使用
{{resp.name}}
in your template. 在您的模板中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.