수정 4번째...

This commit is contained in:
최준흠 2022-08-23 16:24:36 +09:00
parent b9dd346275
commit deddafd93a
2 changed files with 180 additions and 77 deletions

View File

@ -6,5 +6,4 @@ import { BootstrapVue3 } from 'bootstrap-vue-3'
import 'bootstrap/dist/css/bootstrap.css' import 'bootstrap/dist/css/bootstrap.css'
import 'bootstrap-vue-3/dist/bootstrap-vue-3.css' import 'bootstrap-vue-3/dist/bootstrap-vue-3.css'
createApp(App).use(store).use(router).use(BootstrapVue3).mount('#app') createApp(App).use(store).use(router).use(BootstrapVue3).mount('#app')

View File

@ -1,85 +1,140 @@
<template> <template>
<!-- 참조: https://codesandbox.io/s/3v0m1?file=/src/components/board/BoardList.vue --> <!-- 참조: https://codesandbox.io/s/3v0m1?file=/src/components/board/BoardList.vue -->
<div> <div>
<div class="row"> <b-container fluid>
<div class="col justify-content-md-center"> <b-row>
<div class="input-group"> <b-col lg="6" class="my-1">
<span class="input-group-text" id="basic-addon3">PerPage</span> <b-form-group
<input type="text" class="form-control" v-model="perPage" /> label="Sort"
</div> label-for="sort-by-select"
</div> label-cols-sm="3"
<div class="col"> label-align-sm="right"
<div class="input-group flex-nowrap"> label-size="sm"
<input type="text" class="form-control" v-model="searchString" /> class="mb-0"
<span class="input-group-text" id="basic-addon2" @click="searchClick" v-slot="{ ariaDescribedby }"
>검색</span
> >
<b-input-group size="sm">
<b-form-select
id="sort-by-select"
v-model="sortBy"
:options="sortOptions"
:aria-describedby="ariaDescribedby"
class="w-75"
>
<template #first>
<option value="">-- none --</option>
</template>
</b-form-select>
<b-form-select
v-model="sortDesc"
:disabled="!sortBy"
:aria-describedby="ariaDescribedby"
size="sm"
class="w-25"
>
<option :value="false">Asc</option>
<option :value="true">Desc</option>
</b-form-select>
</b-input-group>
</b-form-group>
</b-col>
<b-col sm="5" md="6" class="my-1">
<b-form-group
label="Per page"
label-for="per-page-select"
label-cols-sm="6"
label-cols-md="4"
label-cols-lg="3"
label-align-sm="right"
label-size="sm"
class="mb-0"
>
<b-form-select
id="per-page-select"
v-model="perPage"
:options="perPageOptions"
size="sm"
></b-form-select>
</b-form-group>
</b-col>
<div class="col">
<div class="input-group flex-nowrap">
<input type="text" class="form-control" v-model="searchString" />
<span
class="input-group-text"
id="basic-addon2"
@click="searchClick"
>검색</span
>
</div>
</div> </div>
</div> </b-row>
</div> <b-row class="overflow-auto">
<div class="overflow-auto"> <b-table
<b-table :items="items"
:fields="fields" :fields="fields"
:items="items" :per-page="perPage"
:per-page="perPage" :current-page="currentPage"
:current-page="currentPage" :filter="filter"
:striped="striped" :filter-included-fields="filterOn"
:hover="hover" :filtered="onFiltered"
:bordered="bordered" :sort-direction="sortDirection"
:dark="dark" :busy="isBusy"
:head-variant="headVariant" :striped="striped"
> :hover="hover"
<template #cell(index)="data"> :bordered="bordered"
{{ data.index + 1 }} :dark="dark"
</template> :head-variant="headVariant"
</b-table> >
<b-pagination <template #cell(index)="data">
@page-click="pageClick" {{ data.index + 1 }}
v-model="currentPage" </template>
:total-rows="getTotal" <template #table-busy>
:per-page="perPage" <div class="text-center text-danger my-2">
first-text="First" <b-spinner class="align-middle"></b-spinner>
prev-text="Prev" <strong>Loading...</strong>
next-text="Next" </div>
last-text="Last" </template>
use-router </b-table>
></b-pagination> <b-pagination
{{ total }} @page-click="pageClick"
</div> v-model="currentPage"
:total-rows="total"
:per-page="perPage"
></b-pagination>
</b-row>
<b-button @click="toggleBusy">Toggle Busy State</b-button>
</b-container>
</div> </div>
</template> </template>
<script> <script>
// : https://cdmoro.github.io/bootstrap-vue-3/components/
import axios from 'axios' import axios from 'axios'
export default { export default {
components: {}, components: {},
data() { data() {
return { return {
perPage: 5, // items: [],
currentPage: 1, //
total: 0,
searchString: '',
striped: true,
hover: true,
bordered: true,
dark: false,
headVariant: 'dark',
fields: [ fields: [
{ { key: 'index', label: '번호' },
key: 'index',
label: '번호'
},
{ {
key: 'title', key: 'title',
label: '타이틀', label: '타이틀',
sortable: true, sortable: true,
sortDirection: 'desc' sortDirection: 'desc'
}, },
{ key: 'content', label: '내용' }, {
key: 'content',
label: '내용',
sortable: true,
sortDirection: 'desc'
},
{ {
key: 'is_done', key: 'is_done',
label: '사용여부', label: '사용여부',
formatter: (value) => { formatter: (value, key, item) => {
return value.toLowerCase() === 'true' ? 'Yes' : 'No' return value.toLowerCase() === 'true' ? 'Yes' : 'No'
}, },
sortable: true, sortable: true,
@ -87,20 +142,47 @@ export default {
filterByFormatted: true filterByFormatted: true
}, },
// { key: 'updateAt', label: '' }, // { key: 'updateAt', label: '' },
{ key: 'createdAt', label: '登録日時' } {
key: 'createdAt',
label: '登録日時',
sortable: true,
sortDirection: 'desc'
}
], ],
items: [] total: 0,
perPage: 5, //
perPageOptions: [5, 10, 15, { value: 100, text: 'Show a lot' }],
currentPage: 1, //
searchString: '',
//
striped: true,
hover: true,
bordered: true,
dark: false,
headVariant: 'dark',
isBusy: false,
sortBy: '',
sortDesc: false,
sortDirection: 'asc',
filter: null,
filterOn: []
} }
}, },
setup() {}, setup() {},
created() { created() {},
this.list() mounted() {
// var vm = this
// setTimeout(function () {
// vm.records = vm.getDatas()
// }, 1000)
this.getDatas()
this.total = this.items.length
}, },
mounted() {},
unmounted() {}, unmounted() {},
methods: { methods: {
list() { async getDatas() {
axios this.isBusy = true
const items = await axios
.get('http://localhost:3000/todo', { .get('http://localhost:3000/todo', {
params: { params: {
page: parseInt(this.currentPage), page: parseInt(this.currentPage),
@ -109,30 +191,52 @@ export default {
} }
}) })
.then((response) => { .then((response) => {
// console.log(response) return response.status === 200 ? response.data : []
this.currentPage = response.data.page
this.perPage = response.data.per_page
this.searchString = response.data.searchString
this.total = response.data.total
this.items = response.data.rows
}) })
.catch((err) => { .catch((err) => {
console.log(err) console.log(err)
return []
}) })
console.log(items)
this.total = items.total
// console.log(this.total)
this.items = items.rows
// console.log(JSON.stringify(items))
this.isBusy = false
},
searchClick() {
this.currentPage = 1
this.getDatas()
}, },
pageClick(button, page) { pageClick(button, page) {
console.log(button) console.log(button)
this.currentPage = page this.currentPage = page
this.list() this.getDatas()
}, },
searchClick() { toggleBusy() {
this.isBusy = !this.isBusy
console.log('isBusy:' + this.isBusy)
},
sortingChanged(ctx) {
// ctx.sortBy ==> Field key for sorting by (or null for no sorting)
// ctx.sortDesc ==> true if sorting descending, false otherwise
},
onFiltered(filteredItems) {
// Trigger pagination to update the number of buttons/pages due to filtering
console.logs(filteredItems)
this.totalRows = filteredItems.length
this.currentPage = 1 this.currentPage = 1
this.list()
} }
}, },
computed: { computed: {
getTotal() { sortOptions() {
return this.total // Create an options list from our fields
return this.fields
.filter((f) => f.sortable)
.map((f) => {
return { text: f.label, value: f.key }
})
} }
} }
} }