如何返回到分页页面?

问题描述

使用Laraver惯性Vue

我使用带有分页帖子列表的Vue。对于每个帖子,我只从数据库中加载几列,例如标题和作者。然后,我访问url以在列表中加载所选帖子的详细信息。我这样做是使用带有延迟加载功能的访问URL。之后,我准备编辑帖子而无需重新加载整个页面。帖子更新后,我将其提交并正确保存到数据库中。之后,我可以返回页面。一切都发生了,列表上没有任何重新加载。 为了能够懒惰地在特定的帖子上加载细节,我的on控制器就是这样。

class PostController extends Controller
{
    public function Index($id = null)
    {
        $this->id = $id;
        return Inertia::render('Posts/Index',[
            'posts' => Post::select('id','title','created_at')
                ->addSelect([
                    'userfirstname' => User::select('firstname')->whereColumn('id','posts.user_id'),'userlastname' => User::select('familyname')->whereColumn('id','posts.user_id')
                ])
                ->orderBy('created_at','DESC')
                ->paginate(10),//lazily evaluated
            'details' => function () {
                if ($this->id) {
                    $post = Post::find($this->id);
                } else {
                    $post = null;
                }
                return $post;
            },]);
    }

    public function Update(Request $request)
    {
       $request->validate([
           'id'=>'required','abstract'=>'required',//TODO :to be completed
       ]);
       $post=Post::find($request->input('id'));
       $post->abstract=$request->input('abstract');
       $post->title=$request->input('title');
       //TODO to be completed
       $post->save();
       return Redirect::back();
    }
}

以及我用于加载页面的方法和详细信息如下:

    //visit this url to get the lazzy evaluation of post details
    if (to_visit) {
        this.$inertia
            .visit(`/posts/${to_visit}`,{
                method: "get",data: {},replace: false,preserveState: true,preserveScroll: true,only: ["details"],headers: {}
            })
            .then(to_visit => {
                console.log("fetched " + this.details.title);
            });
    }

},updatePost(form) {
    console.log("form submitted");
    this.$inertia.visit(`/post`,{
        method: "put",data: form,only: [],headers: {}
    });
},

只要我更新的特定帖子在首页上,此方法就可以正常工作,但是当它在列表上的任何其他分页页面上时,帖子保存都可以,但我不会在分页页面上返回,但总是在第一个。 很高兴听到解决方案!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)