1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
   | <template>   <div>     <b-row class="mb-3">       <b-col         md="3"         offset-md="9">         <b-form-select           v-model="meta.per_page"           :options="options"/>       </b-col>     </b-row>
      <b-table       :items="signatures"       :fields="fields"       striped       hover>       <template         slot="action"         slot-scope="signature">         <b-button           size="sm"           variant="danger"           @click.prevent="destroy(signature.item.id)">刪除</b-button>       </template>     </b-table>
      <b-pagination       v-model="meta.current_page"       :first-text="meta.first_text"       :prev-text="meta.prev_text"       :next-text="meta.next_text"       :last-text="meta.last_text"       :limit="meta.limit"       :per-page="meta.per_page"       :total-rows="meta.total_rows"       align="center"/>   </div> </template>
  <script> export default {   layout: 'app',   data() {     return {       url: process.env.baseUrl + '/signatures',       signatures: [],       meta: {         current_page: 1,         first_text: '第一頁',         prev_text: '前一頁',         next_text: '下一頁',         last_text: '最後頁',         limit: 7,         per_page: 10,         total_rows: 0       },       options: [         { value: 5, text: 5 },         { value: 10, text: 10 },         { value: 15, text: 15 }       ],       fields: [         { key: 'id', label: '編號' },         { key: 'name', label: '名字' },         { key: 'content', label: '內容' },         { key: 'action', label: '' }       ]     }   },   watch: {     'meta.current_page': function() {       this.fetch()     },     'meta.per_page': function() {       this.fetch()     }   },   created() {     this.fetch()   },   methods: {     fetch() {       this.$axios.get(this.url + '?page=' + this.meta.current_page + '&per_page=' + this.meta.per_page)         .then(({data}) => {           this.signatures = data.data           this.meta.total_rows = data.meta.total         })     },     destroy(id) {       if (confirm('確定刪除?')) {         this.$axios.delete(this.url + '/' + id)           .then(() => {             this.data = this.lodash.remove(this.data, function (data) {               return data.id !== id             })             this.fetch(this.url + '?page=' + this.meta.current_page)           })       }     }   } } </script>
   |