【发布时间】:2019-11-09 13:34:29
【问题描述】:
当我在 get 方法中连接 axion 时,我从我的 api 得到响应,我想在网站上打印信息。
我试图改变这一行:
.then(response => (this.username= response.data.username)) or this
.then(response => (this.username= response.data[0].username)) or this
.then(response => (this.username= response.data.username[0]))
脚本
<script>
import axios from 'axios';
export default {
name: "acount",
el: '#app',
data() {
return {
username: null,
pseudo: null,
email: null,
date: null,
};
},
mounted () {
axios
.get('http://127.0.0.1:8080/api/user/65', {
headers: {
token: ''
}
})
.then(response => (this.username= response.data[0].username[0]))
.then(response => (this.pseudo = response.data.pseudo))
.then(response => (this.email = response.data.email))
.then(response => (this.date = response.data.create_at))
}
}
</script>
【问题讨论】:
-
目前还不清楚是什么问题。问题应包含明确的问题陈述。标题看不懂。请参阅stackoverflow.com/help/how-to-ask