HTML页面中的Vue组件

时间:2019-02-24 02:47:32

标签: php laravel vue.js http-status-codes

我正在现有的HTML页面中创建一个vue注释组件,但是我得到的是500个内部服务器错误

正在显示的页面的URL为http://sim.admin/viewjournalentry

vue组件最终调用以下http://sim.admin/viewjournalentry/comments(因此发生内部服务器错误)

我的api.php文件包含以下路由

use Illuminate\Http\Request;
use App\JournalComment;

Route::group(['middleware' => 'api'], function(){
    //Get comments
    Route::get('comments', function(){
        return JournalComment::latest()->orderBy('created_at', 'desc')- 
        >get();
    });

    //Get Single comment
    Route::get('comments/{id}', function(){
        return JournalComment::findOrFail($id);
    });

    //Add comment
    Route::post('comments/store', function(Request $request){
        return JournalComment::create(['comment' => $request- 
            >input['comment']]);
    });

    //Update Comment
    Route::patch('comments/{id}', function(Request $request, $id){
        JournalComment::findOrFail($id)->update(['comment' => $request- 
            >input(['comment'])]);
    });

    //Delete Comments
    Route::delete('comments/{id}', function($id){
        return JournalComment::destroy($id);
    });
});

Comments.vue文件包含以下代码

<template>
    <div>
        <h2>Trade Comments</h2>
        <form action="#" @submit.prevent="edit ? updateComment(comments.id) : 
            createComment()">
        <div class="form-group">
            <label>Comment</label>
            <textarea v-model="comments.comment" class="form-control" 
              placeholder="write a comment..." rows="3"></textarea>
        </div>
        <div class="form-group">
            <button v-show="!edit" type="submit" class="btn btn-primary">Add 
             Comment</button>
            <button v-show="edit" type="submit" class="btn btn- 
            primary">Update Comment</button>
        </div>
        </form>
    </div>
</template>
<script>
export default {
    data: function() {
        return {
            edit: false,
            list:[],
            comments:{
                id:'',
                comment:''
            }
        }
    },
    mounted: function() {
        console.log('Comments Component Loaded...');
        this.fetchCommentList();
    },
    methods: {
        fetchCommentList:function(){
            console.log('Fetching Comments');
            axios.get('comments')
                .then(function(response){
                    console.log(response.data);
                    this.list = response.data;
            }).catch(function(error){
                console.log(error);
            });
        },
    }
}
</script>

模型文件的设置如下

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class JournalComment extends Model
{
    public function journal(){
        return $this->belongsTo('App\Journal', 'journal_id');
    }
}

0 个答案:

没有答案