在Vue组件(Users.vue)中得到此信息。调用fetchUsers-function但是永远不会调用回调函数。我试图附加.error() - func但我收到this.$http.get(...).error is not a function
的错误。
<template>
<div class="panel panel-default">
<div class="panel-heading">Användare</div>
<div class="panel-body">
<table class="table">
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr v-for="user in users">
<td>{{ id }}</td>
<td>{{ name }}</td>
<td>{{ email }}</td>
</tr>
</tbody>
</table>
</div>
</div>
</template>
<script>
export default {
name: "Users",
ready() {
console.log('Component ready.')
this.fetchUsers();
},
methods: {
fetchUsers: function() {
console.log("Fetching users...");
this.$http.get('/api/user', (data) => {
this.$set("users", data);
});
}
}
}
</script>
我使用的是与Vue.js一起提供的Laravel框架。不知道它是如何工作的,但是我在网络浏览器中显示了组件,我从控制台输出了这段代码。
答案 0 :(得分:1)
我相信您需要添加vue-resources,尝试添加
$location = !empty($_SESSION['location']) ? $_SESSION['location']:'default_location';
$mysqli->real_escape_string($location);
$mysqli->query("select * from bookings where origin = $location");
<script src="https://cdn.jsdelivr.net/vue.resource/0.9.3/vue-resource.min.js"></script>
或试试这个
this.$http.get('/api/user', (data) => {
this.$set("users", data);
}, (error) => {
console.log(error)//check errors
});