vuetify datatable v-select laravel - PullRequest
       15

vuetify datatable v-select laravel

0 голосов
/ 01 мая 2020

У нас есть дата от laravel бэкэнда. Нам нужно отсортировать данные за месяц. На Laravel сайте у нас есть:

$per_page = $request->per_page;//? $request->per_page : 10;
$sortBy = $request->sort_by;
$orderBy = $request->order_by;
$month = $request->month;
return response()->json(['o2attendances' => O2attendance::whereMonth('date' , $month)->whereYear('date' , Carbon::today()->year)->orderBy($sortBy, $orderBy)->paginate($per_page)], 200);

А на Vuejs у нас есть:

<v-select
            :items="mesiace"
            item-text="text"
            item-value="value"
            hide-details
            height="20"
            @change="sortValue"
            filter
></v-select>
mesiace: [
      { text: "januar", value: "01" },
      { text: "februar", value: "02" },
      { text: "marec", value: "03" },
      { text: "april", value: "04" },
      { text: "maj", value: "05" },
      { text: "jun", value: "06" },
      { text: "jul", value: "07" },
      { text: "august", value: "08" },
      { text: "september", value: "09" },
      { text: "oktober", value: "10" },
      { text: "november", value: "11" },
      { text: "december", value: "12" }
    ],
methods:
    sortValue() {
      const sortBy =
        this.options.sortBy.length == 0 ? "date" : this.options.sortBy[0];
      const orderBy =
        this.options.sortDesc.length > 0 && this.options.sortDesc[0]
          ? "asc"
          : "desc";
      axios
        .get(`https://api/api/v1/o2attendances/all`, {
          params: {
            sort_by: sortBy,
            order_by: orderBy,
            month: this.mesiace.value
          }
        })
        .then(response => {
          this.o2attendances = response.data.o2attendances;
        });
    },

, когда мы меняем месяц sortValue: «04» или «05», то его работает, но this.mesiace.value его не работает.

1 Ответ

0 голосов
/ 01 мая 2020

Это работает:

 <v-select
        :items="mesiace"
        v-model="mesiac"
        item-text="text"
        item-value="value"
        hide-details
        height="20"
        @change="sortValue"
        filter
      ></v-select>

добавлена ​​v-модель

mesiac: null,

и

methods:
sortValue() {
  const sortBy =
    this.options.sortBy.length == 0 ? "date" : this.options.sortBy[0];
  const orderBy =
    this.options.sortDesc.length > 0 && this.options.sortDesc[0]
      ? "asc"
      : "desc";
  axios
    .get(`https://api/api/v1/o2attendances/all`, {
      params: {
        sort_by: sortBy,
        order_by: orderBy,
        month: this.mesiac
      }
    })
    .then(response => {
      this.o2attendances = response.data.o2attendances;
    });
},
...