Ver Código Fonte

product detail

tum 2 anos atrás
pai
commit
4d206313d6
2 arquivos alterados com 76 adições e 3 exclusões
  1. 53 0
      src/components/ProductDetail.vue
  2. 23 3
      src/views/ProductListPage.vue

+ 53 - 0
src/components/ProductDetail.vue

@@ -1,2 +1,55 @@
1 1
 <template>
2
+  <ion-header>
3
+    <ion-toolbar>
4
+      <ion-buttons slot="start">
5
+        <ion-button color="medium" @click="cancel">Cancel</ion-button>
6
+      </ion-buttons>
7
+      <ion-title>Modal</ion-title>
8
+      <ion-buttons slot="end">
9
+        <ion-button @click="confirm">Confirm</ion-button>
10
+      </ion-buttons>
11
+    </ion-toolbar>
12
+  </ion-header>
13
+  <ion-content class="ion-padding">
14
+    <ion-item>
15
+      <ion-label position="stacked">Your name</ion-label>
16
+      {{ name }}
17
+      <ion-input v-model="name" placeholder="Your name"></ion-input>
18
+    </ion-item>
19
+  </ion-content>
2 20
 </template>
21
+
22
+<script setup lang="ts">
23
+  import {
24
+    IonContent,
25
+    IonHeader,
26
+    IonTitle,
27
+    IonToolbar,
28
+    IonButtons,
29
+    IonButton,
30
+    IonItem,
31
+    IonLabel,
32
+    IonInput,
33
+    modalController,
34
+    onIonViewWillEnter, 
35
+  } from '@ionic/vue';
36
+  import { ref, onMounted } from 'vue'
37
+
38
+const props = defineProps(['pid'])
39
+
40
+//console.log(pid)
41
+
42
+let name = ref("xxx")
43
+function cancel(){
44
+  return modalController.dismiss(null, 'cancel');
45
+}
46
+function confirm(){
47
+  return modalController.dismiss(name.value, 'confirm');
48
+}
49
+onMounted(() => {
50
+//onIonViewWillEnter(() => {
51
+  console.log("on mounted")
52
+  console.log(props.pid)
53
+})
54
+
55
+</script>

+ 23 - 3
src/views/ProductListPage.vue

@@ -16,10 +16,10 @@
16 16
     </ion-header>
17 17
     <ion-grid>
18 18
       <ion-row>
19
-        <ion-col size="6" v-for="c in prods">
19
+        <ion-col size="6" v-for="(c, index) in prods"  :key="index" @click="openModal">
20 20
           <ion-img :src="c.cover_image_str"></ion-img>
21 21
           <ion-label class="ion-text-wrap">
22
-            {{ c.name }}
22
+            {{ c.name }} {{ message }}
23 23
           </ion-label>
24 24
         </ion-col>
25 25
       </ion-row>
@@ -28,7 +28,9 @@
28 28
 </ion-page>
29 29
 </template>
30 30
 <script setup lang="ts">
31
-import { IonPage, IonHeader, IonToolbar, IonTitle, IonContent, IonBackButton, IonButtons, onIonViewWillEnter, IonCard, IonCardHeader, IonCardTitle, IonCardSubtitle, IonCardContent, IonRow, IonGrid, IonCol, IonImg, IonButton, IonLabel} from '@ionic/vue';
31
+import { IonPage, IonHeader, IonToolbar, IonTitle, IonContent, IonBackButton, IonButtons, onIonViewWillEnter, IonCard, IonCardHeader, IonCardTitle, IonCardSubtitle, IonCardContent, IonRow, IonGrid, IonCol, IonImg, IonButton, IonLabel, modalController} from '@ionic/vue';
32
+
33
+import ProductDetail from '@/components/ProductDetail.vue'
32 34
 
33 35
 import axios from 'axios';
34 36
 import { API_URL } from '../api_config';
@@ -40,10 +42,28 @@ const { cat  } = route.params;
40 42
 let prods = ref([])
41 43
 onIonViewWillEnter( async() => {
42 44
 })
45
+
46
+let message = ''
43 47
 onMounted( async() => {
44 48
   console.log(cat)
45 49
   const res = await axios.get(API_URL+`fn_products/?format=json&cat=${cat}`)
46 50
   prods.value = res.data.results
47 51
   console.log(prods)
48 52
 })
53
+
54
+const openModal = async () => {
55
+  const modal = await modalController.create({
56
+    component: ProductDetail,
57
+    componentProps: {pid: 5}, 
58
+  });
59
+  modal.present();
60
+
61
+  const { data, role } = await modal.onWillDismiss();
62
+
63
+  if (role === 'confirm') {
64
+    console.log(data.value)
65
+    message = `Hello, ${data}!`;
66
+    console.log(message)
67
+  }
68
+}
49 69
 </script>