This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data() { | |
return { | |
currentPage: 1, | |
itemsPerPage: 1, | |
dataAmount: 0, | |
cities: [ | |
{ | |
id: 1, | |
name: "Paris" | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
methods: { | |
changeCurrentPage(pageNumber) { | |
this.currentPage = pageNumber | |
}, | |
parseItemsPerPage() { | |
this.itemsPerPage = +this.itemsPerPage; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
computed: { | |
totalPages: function() { | |
return Math.ceil(this.dataAmount / this.itemsPerPage) | |
}, | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
computed: { | |
totalPages: function() { | |
return Math.ceil(this.dataAmount / this.itemsPerPage) | |
}, | |
currentContents: function() { | |
// 檢查 Array 的資料是否為空 | |
if (!this.cities || this.cities.length != this.cities.length) { | |
return; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const start = this.currentPage * this.itemsPerPage - this.itemsPerPage; | |
const end = start + this.itemsPerPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
computed: { | |
totalPages() { | |
return Math.ceil(this.dataAmount / this.itemsPerPage); | |
}, | |
currentContents() { | |
if (!this.cities || this.cities.length != this.cities.length) { | |
return; | |
} | |
this.dataAmount = this.cities.length; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ul> | |
<li v-for="(city, id) in currentContents" :key="id"> | |
{{ city.name }} | |
</li> | |
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="btn-group"> | |
<button | |
v-for="pageNumber in totalPages" | |
@click="changeCurrentPage(pageNumber)" | |
> | |
{{ pageNumber }} | |
</button> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<select @change="parseItemsPerPage" v-model="itemsPerPage" name="dog-names" id="item-per-page"> | |
<option value="1">1</option> | |
<option value="3">3</option> | |
<option value="5">5</option> | |
<option value="10">10</option> | |
</select> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const store = createStore({ | |
state: { | |
user: [] | |
}, | |
mutations: { | |
changeUser (state, newUser) { | |
state.user = newUser; | |
} | |
}, | |
actions: { |