使用Laravel和vue.js可视化数据的表
我一直在努力制作一个简单的VUE JS和Laravel数据显示网页,这是为了在表中显示所有数据,但是我没有运气,所以我已经发布了这个问题,但是现在错误已更改,因此我再次发布。到达 /API目录时,我都可以看到所有JSON数据,甚至在所有页码上都需要的分页所需的不同页面,但是当我进入控制台时,我会收到JSON错误:
Source map error: Error: JSON.parse: unexpected character at line 1 column 1 of the JSON
data
Resource URL: http://127.0.0.1:8000/js/app.js
Source Map URL: laravel-vue-pagination.common.js.map
不确定这是什么手段或是否与未显示在表上显示的数据有任何相关性或还有其他内容。另外,当我加载代码编辑器时,我的vue扩展程序说它找不到 tsconfig.json
或 jsconfig.json
在项目文件中。
因此,这里对任何帮助都非常感谢:home.blade.php:
@extends('layouts.app')
@section('content')
<div class="container" id="app">
<home-component></home-component>
</div>
@endsection
homecomponent:
<template>
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">Home component</div>
<ul>
<li v-for="post in laravelData.data" :key="post._id">{{ post.STATUS }}</li>
</ul>
<Pagination :data="laravelData" @pagination-change-page="getResults" />
</div>
</div>
</div>
</div>
</template>
<script>
import LaravelVuePagination from 'shetabit-laravel-vue-pagination';
export default{
components: {
'Pagination': LaravelVuePagination
},
data() {
return {
laravelData: {}
};
},
mounted(){
this.getResults();
},
methods:{
getResults(page = 1) {
axios.get('api/users?page=' + page)
.then(response => {
this.laravelData = response.data;
});
}
},
}
</script>
api路由:
Route::middleware('api')->group(function () {
Route::get('/home', [PostController::class, 'home']);
});
Web路由:
Route::get('{any}', function () {return view('home');})->where('any', '.*');
postcontroller
public function home() {
$posts = Post::paginate(4);
return response()->json($posts);
}
如果您需要版本使用
拉拉维尔:8.83
VUE:“^2.6.12”
laravel-vue-pagination:“^2.3.1”
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Aright,我刚刚创建了一个新项目,一切都在起作用,因此这是您显然可以忽略
laravel
安装的步骤。vue
在app.js
中设置,如下:(您可以忽略)example-component.vue中
:(不要忘记在vue
component中导入您的组件)welcome.blade.blade.app
添加元素和脚本标签以查看,(我没有添加CSS
,因为我只想测试vue
app)api.php
(您应该通过控制器调用api
这是推荐的方法,我使用api.php
直接完成了此操作,以免浪费时间以及此处的代码和描述行。)因此,您已经安装了
> laravel
项目,如果您不确定分页式组件,请按照以下内容删除它:并按照我说:
我没有安装原始的杂货您已经安装了以前的安装,以确保您不会结束创建一个新项目或等。
编辑02: github链接
Aright, I've just created a new project and everything was working so here's the steps which you can obviously ignore
Laravel
installation.VUE
setup inapp.js
as below : (you can ignore)Example-Component.vue
: (don't forget to import your component inVUE
component)welcome.blade.app
Add Element and script tag to view, (I haven't addedCSS
because i only wanted to testVUE
app)api.php
(You should call yourAPI
via controller which is the recommended way, I've done this usingapi.php
directly to don't waste time and lines of codes and description in here.)So, you've already installed your
Laravel
project, if you're not sure about your paginate component, just remove It like below :And install it as i said :
I haven't installed the original paginate to make sure you get what you want base on what you've installed before, to make sure you don't end to creating a new project or etc.
Edit 02 : Github Link
i此错误是由于JSON引起的,您已从控制器返回您
,您可以在 mdn文档
您可以通过添加您的控制器的响应来尝试一下
,也可以尝试一下
I This error is caused due to json you have returned from controller
you check out more at MDN docs
you can try this out by adding in you controller response of getting post
And Also try this out