show each data for favorites page

This commit is contained in:
p11037 2023-11-30 00:07:02 +07:00
parent ff5333c715
commit 19ba190ced
2 changed files with 57 additions and 62 deletions

View file

@ -37,7 +37,7 @@
<v-list-item-title class="text-decoration-underline">{{nearestStructureData.lon}} , {{nearestStructureData.lat}}</v-list-item-title> <v-list-item-title class="text-decoration-underline">{{nearestStructureData.lon}} , {{nearestStructureData.lat}}</v-list-item-title>
</v-list-item> </v-list-item>
<v-list-item> <!-- <v-list-item>
<template v-slot:prepend> <template v-slot:prepend>
<v-avatar> <v-avatar>
<img :src="detial[2].icon" <img :src="detial[2].icon"
@ -46,7 +46,7 @@
</v-avatar> </v-avatar>
</template> </template>
<v-list-item-title>{{detial[2].title}}</v-list-item-title> <v-list-item-title>{{detial[2].title}}</v-list-item-title>
</v-list-item> </v-list-item> -->
</v-list> </v-list>
@ -254,7 +254,7 @@ export default {
if (this.isLocationRequested && !this.userLocation) { if (this.isLocationRequested && !this.userLocation) {
return 'Requesting location...'; return 'Requesting location...';
} else if (this.userLocation) { } else if (this.userLocation) {
return `${this.userLocation.lat.toFixed(6)}, ${this.userLocation.lon.toFixed(6)}`; return `${this.userLocation.lon.toFixed(6)}, ${this.userLocation.lat.toFixed(6)}`;
} }
return 'Location not available'; return 'Location not available';
}, },

View file

@ -1,63 +1,58 @@
<template> <template>
<div> <div>
<h1>My Favorites</h1> <h1>Favorites</h1>
<ul> <ul class="favorite-list">
<li v-for="(favorite, index) in favorites" :key="index"> <li v-for="(favorite, index) in favorite" :key="index" class="favorite-item">
<p>Favorite {{ index + 1 }}:</p> {{ favorite.place_name }} <!-- แสดงขอม favorites ตามความเหมาะสม -->
<p>Favorite ID: {{ favorite.place_name }}</p> </li>
<p>Favorite Name: {{ favorite.place_name }}</p> </ul>
<!-- แสดงขอมลเพมเตมหร field นๆ ตามตองการ --> </div>
</li> </template>
</ul>
</div> <script>
</template> import { ref, onMounted } from 'vue';
<script> export default {
import { ref, onMounted } from 'vue'; setup() {
const favorite = ref([]);
export default {
setup() { onMounted(async () => {
const favorites = ref([]); try {
const currentUser = JSON.parse(sessionStorage.getItem('current_user'));
onMounted(async () => {
try { if (currentUser && currentUser.id) {
const currentUser = JSON.parse(sessionStorage.getItem('current_user')); const response = await fetch(`https://little-lines-backend.techtransthai.org/api/favorites/${currentUser.id}`);
if (currentUser && currentUser.id) { if (!response.ok) {
const response = await fetch(`https://little-lines-backend.techtransthai.org/api/favorites/${currentUser.id}`); throw new Error('Failed to fetch favorites');
if (!response.ok) {
throw new Error('Failed to fetch favorites');
}
const data = await response.json();
favorites.value = data.favorites;
console.log(data);
} }
} catch (error) {
console.error(error); const data = await response.json();
favorite.value = data;
} }
}); } catch (error) {
console.error(error);
return { }
favorites });
};
} return {
}; favorite
</script> };
<style scoped>
/* สามารถใส่ style ได้ตามต้องการ */
/* ตัวอย่าง */
ul {
list-style-type: none;
padding: 0;
} }
};
li { </script>
margin-bottom: 20px;
border: 1px solid #ccc; <style>
padding: 10px; /* CSS เพื่อแสดงแต่ละข้อมูลเป็น block */
} .favorite-list {
</style> list-style-type: none;
padding: 0;
}
.favorite-item {
display: block;
padding: 10px;
border: 1px solid #ccc;
margin-bottom: 5px;
}
</style>