【发布时间】:2022-01-04 19:21:07
【问题描述】:
您好 Stackoverflow 社区,
在我的模板中,我尝试显示通过 api 调用接收的数据。当我记录 api 获取响应时,这是我收到的:
现在我尝试使用以下代码在位置显示数据:
{{ userdetails.location.location_name }}
我的脚本如下所示:
data() {
return {
userdetails: [],
};
},
methods: {
getUserData() {
DataService.getUserById()
.then((response) => {
this.userdetails = response.data;
console.log(response);
})
...
created() {
this.getUserData();
},
奇怪的是,我可以在我的应用程序中看到 location_name。但我也收到错误:
我想我在某个地方弄错了,但我找不到。你知道我做错了什么吗?
提前感谢您的所有提示!
【问题讨论】:
-
您也可以指定确切的 location_name 作为您的数据,
data(){ return { userdetails :{ location : { location_name : 'test' } } } -
@TheFool 我的意思是 vue 的小胡子语法 (vuejs.org/v2/guide/syntax.html#Text)
标签: javascript api vue.js mustache