laravel爱可信vue.js /错误连接到数据库
(我编辑我的代码,它的工作!)laravel爱可信vue.js /错误连接到数据库
我试图让我的数据库对象与Vue公司和Laravel使用它们。
我data.blade.php:slight_smile:
<!DOCTYPE html>
<html>
<head>
<title> Tab test</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.5.1/css/bulma.css">
</head>
<body>
<div id="app">
<users></users>
</div>
</body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.4.2/vue.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js"></script>
<script src="/js/customers.js"></script>
</html>
我customers.js
Vue.component('users',{
template : `
<table class="users">
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th>Email</th>
<th>Creation Data</th>
</tr>
</thead>
<tbody>
<tr v-for="user in users">
<th>{{ user.id }}</th>
<th>{{ user.lastname }}</th>
<th>{{ user.email }}</th>
<th>{{ user.created_at }}</th>
</tr>
</tbody>
</table>
`,
data: function() {
return {
users: []
}
},
created: function() {
this.getUsers();
},
methods: {
getUsers: function(){
axios.get("/apps").then((response) => {this.apps = response.data})
}
}
}),
new Vue({
el: '#app',
});
而且我api.php
Route::get('/users', function(){
return App\User::all();
})->name('api_users');
我的错误是:
你有什么想法吗?我认为这是axios的问题,但我不知道如何解决它。 ?
感谢您的任何意见或解决方案:)
{{route('api_users') }}
是叶片功能,不能在你的.js
文件中使用。
你可以:
- 硬编码的URL
/users
在JavaScript文件 - 结合的路线,在刀片和访问前端它通过有
- 等
感谢您的回复如此之快!像那样:axios.get(“/ customers/list/data”) .then(response => {this.users = response.data.users}) }? – Virtualbees
根据您的路线'api_users'是'/ users'而不是'/ customers/list/data',但这是一般的想法是的 – Quezler
对不起,我是vue.js中的新人,我不明白如何做到这一点.... – Virtualbees
'axios.get (“{{route('api_users')}}”)'是你的问题。你需要传递你想要'axios'的实际url来发出请求到 – thanksd