繁体   English   中英

Laravel vue惯性创建分页搜索时出错

[英]Error in Laravel vue inertia creating search with pagination

我是将 Laravel 8 与 vuejs 和惯性 js 一起使用的初学者。 我正在尝试制作分页搜索表。 我正在按照教程来实现这一点,但我有错误。

这是我来自 vue 的绑定输入类型:

<input type="text" name="table_search" class="form-control float-right" placeholder="Search" v-model="term" @keyup="search">

这是我来自 vue 的整个脚本:

<script>
    import AppLayout from '@/Layouts/AppLayout'
    import Paginator from "@/Components/Paginator";

    export default {
        data() {
          return {
            term: ''
          }
        },

        props: {
          members:Object,
          filters: Object
        },

        components: {
            AppLayout,
            Paginator,
            // JetPagination
        },

        methods: {
          search() {
            this.$inertia.replace(this.$route('member.index', {term: this.term}))
          }
        }


    }
</script>

现在在我的 laravel controller 中,这是我从教程中遵循的:

public function index(Request $request)
    {           
        return Inertia::render('Members/Member', [
            'members' => Member::with('user')->when($request->term, function($query, $term) {
                $query->where('firstname', 'LIKE', '%'.$term.'%');
            })->paginate()
        ]);
    }

我的控制台中有问题/警告/错误:

[Vue warn]: Unhandled error during execution of native event handler 
Uncaught TypeError: this.$route is not a function

基于文档

你应该这样做:

export default {

  data() {
     term: '',
     routes: {{ json_encode($routes) }}
  }

  ...

  methods: {
    search() {
      this.$inertia.replace(this.routes('member.index', {term: this.term}))
    }
  }
}

您应该将json_encode传递给您的数据并访问它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM