我有一个外部 api,它返回一个用户的 json,其中包含一些属性,如用户名。我想在我的 vue 方法中使用这个用户名作为 url 参数并定义函数 getUser()。我的问题是参数未定义
这是我的代码
<script>
import Axios from 'axios-observable'
export default {
data () {
return {
appointments: {},
event_counter: 0,
user: ''
},
methods: {
getUser: function () {
Axios
.get('http://127.0.0.1:5000/users/get_user')
.subscribe(response => { this.user = response.data.username })
},
getAppointments: function () {
Axios
.get('http://127.0.0.1:5000/appointments/get_appointments?user=' + this.user)
.subscribe(response => { this.appointments = response.data })
},
fetchData: function () {
setInterval(() => {
this.getAppointments()
}, 150000)
}
},
mounted () {
//this.user = this.getUser()
this.getUser()
this.fetchData()
},
created () {
//this.user = this.getUser()
this.getUser()
this.getAppointments()
}
}
</script>
我尝试了一些变体return response.data
或data: this.getUser()
等。在模板中获取用户{{ user }}
可以正常工作,但没有帮助。我没有来自 vue/electron-vue 的任何语法或运行时错误
任何的想法?