TanStackT
TanStack2y ago
8 replies
ripe-gray

Help with vue query together vue table

Hi, i need help with my implementation of vue query.
I try to fetch data for my useVueTable data.

The problem is that either it executes the query infinite times or the data is not shown in the table.

function fetchTickets(page?: number, filter_title?: string, sort?: "title" | "created_at" | "updated_at" | "status" | "-title" | "-created_at" | "-updated_at" | "-status") {
  return axios.get(route('user.tickets.all', {
    "sort": sort, "filter[title]": filter_title, "page": page
  }))
}


function ticketQuery(page?: number, filter_title?: string, sort?: "title" | "created_at" | "updated_at" | "status" | "-title" | "-created_at" | "-updated_at" | "-status") {
  return useQuery({
    queryKey: ['tickets', page, filter_title, sort],
    queryFn: async () => {
      const d = await fetchTickets(page, filter_title, sort)
      console.log(d.data)
      return d.data
    },
    refetchOnMount: false
  })
}


const table = useVueTable({
      get data() {
        return ticketQuery(1).data?.data ?? []
      },
      columns: columns,
      getCoreRowModel: getCoreRowModel(),
    }
)

and the table is used like this (it is given to a different component):

 <DataTable :table="table"/>

The datatable is basically the one provided by shadcn vue.

and i also see these errors
vue-query composable like "useQuery()" should only be used inside a "setup()" function or a running effect scope. They might otherwise lead to memory leaks.

[Vue warn] onScopeDispose() is called when there is no active effect scope to be associated with.

Thanks for help
Was this page helpful?