【发布时间】:2020-05-31 01:24:20
【问题描述】:
我在将数据从 Node.js 代码传递到 Vue.js 时遇到问题
我的 Vue.js 部分:
<p class="align-self-center m-0">Name</p>
<div v-for="info in infos" v-bind:key="info">
{{info}}
</div>
和 Node.js 部分:
import axios from 'axios';
export default {
name: 'section1',
data () {
return {
infos:""
}
},
mounted(){
let headers = {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
};
axios.get('http://localhost:5000/api/v1/profile/5e21990d8d18cf33f8adf94a',{ headers })
.then( response => {
var user = JSON.parse( response.data ).results[0]
console.log(user)
this.infos = user.name
})
}
}
我想将信息(即 user.name)传递给我的视图。 感谢您的帮助。
【问题讨论】:
-
有什么问题以及预期的行为是什么?
-
在您的数据中,您有一个名为
infos的值,但在您的模板中,您将其称为info。这不是你的问题吗?
标签: node.js vue.js parameter-passing