-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvue_hotel.html
126 lines (120 loc) · 4.89 KB
/
vue_hotel.html
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>旅館民宿-觀光資料(第一版)</title>
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/myall.css">
<link rel="stylesheet" href="css/all.min.css">
</head>
<body>
<div id="app" class="container">
<div class="row mt-3">
<div class="col-12">
<select class="form-select" aria-label="Default select example">
<option selected value="">選擇縣市旅館</option>
<option v-for="(item,key) in regions" :value="item" >{{ item }}</option>
</select>
</div>
</div>
<div class="card mt-3">
<div class="card-header bg-dark ">
<div class="fs-3 text-whitefw-bolder text-white">民宿資料</div>
</div>
</div>
<div class="card-body">
<div class="row">
<div class="col-12">
<div class="row d-flex justify-content-end my-3">
<div class="col-3">
<input type="number" class="form-control" placeholder="輸入搜尋筆數" v-model="numofpage">
</div>
</div>
<ul class="list-group">
<li class="list-group-item"
v-for="(item,key) in filterdata[currentPage]"
v-bind:key="key">{{ key+1 }}.{{ item.Name }}</li>
</ul>
</div>
</div>
</div>
<div class="card-footer">
<div class="row mt-3">
<div class="col-12">
<nav aria-label="Page navigation example">
<ul class="pagination">
<li class="page-item" v-if="currentPage > 0"><a class="page-link" href="#" v-on:click.prevent="currentPage = currentPage - 1"> 上一頁</a></li>
<li class="page-item" v-bind:class="{'active' : currentPage == item-1}" v-for="(item,key) in filterdata.length" v-bind:key="key" ><a class="page-link" href="#" v-on:click.prevent="currentPage = item-1" >{{ item }}</a></li>
<li class="page-item" v-if="currentPage < filterdata.length - 1"><a class="page-link" href="#" v-on:click.prevent="currentPage = currentPage + 1">下一頁</a></li>
</ul>
</nav>
</div>
</div>
</div>
</div>
<script src="js/bootstrap.bundle.min.js"></script>
<script src="js/jquery-3.6.1.min.js"></script>
<script src="js/vue.global.js"></script>
<script src="js/axios.min.js"></script>
<script>
const App = {
data(){
return {
test:'123',
opendata:[],
numofpage:100,
currentPage:0,
regions:[],
city:'',
}
},
created() {
var vm = this;
axios.get('js/hotel_C_f.json')
.then(function (response) {
// handle success
console.log(response);
// console.log(response.data.XML_Head.Infos);
vm.opendata = response.data.XML_Head.Infos.Info;
console.log(vm.opendata);
vm.getRegion();
})
.catch(function (error) {
// handle error
console.log(error);
})
.finally(function () {
// always executed
});
},
methods: {
getRegion(){
var vm = this;
const regions = new Set();
vm.opendata.forEach(function(item,key){
regions.add(item.Region);
});
vm.regions = Array.from(regions);
}
},
computed: {
filterdata(){
var vm = this;
var newdata = [];
vm.opendata.forEach(function(item,key){
if(key % vm.numofpage == 0){
newdata.push([])
}
var page = parseInt(key/vm.numofpage);
newdata[page].push(item);
})
return newdata;
},
}
}
Vue.createApp(App).mount("#app");
</script>
</body>
</html>