File tree Expand file tree Collapse file tree 2 files changed +8
-26
lines changed Expand file tree Collapse file tree 2 files changed +8
-26
lines changed Original file line number Diff line number Diff line change 32
32
* @module CartContents
33
33
* @returns {Object} The Vue.js component object.
34
34
*/
35
- import { computed , ref , onMounted } from " vue" ;
35
+ import { computed } from " vue" ;
36
36
import { useCart } from " @/store/useCart" ;
37
37
38
38
const props = defineProps ({
@@ -43,9 +43,10 @@ const props = defineProps({
43
43
});
44
44
45
45
const cart = useCart ();
46
- const isLoading = ref (true );
47
- const error = ref (null );
48
46
47
+ // Use the store's reactive state directly
48
+ const isLoading = computed (() => cart .loading );
49
+ const error = computed (() => cart .error );
49
50
const cartItems = computed (() => cart .cart );
50
51
51
52
/**
@@ -59,16 +60,6 @@ const handleRemoveProduct = async (key) => {
59
60
} catch (error) {}
60
61
};
61
62
62
- onMounted (async () => {
63
- try {
64
- await cart .refetch ();
65
- } catch (err) {
66
- error .value = err;
67
- } finally {
68
- isLoading .value = false ;
69
- }
70
- });
71
-
72
63
/**
73
64
* Handles updating the quantity of a cart item.
74
65
*
Original file line number Diff line number Diff line change 48
48
</template >
49
49
50
50
<script setup>
51
- import { ref , computed , onMounted } from " vue" ;
51
+ import { computed } from " vue" ;
52
52
import { useCart } from " @/store/useCart" ;
53
53
import { formatPrice } from " @/utils/functions" ;
54
54
55
55
const cart = useCart ();
56
- const isLoading = ref (true );
57
- const error = ref (null );
58
56
57
+ // Use the store's reactive state directly
58
+ const isLoading = computed (() => cart .loading );
59
+ const error = computed (() => cart .error );
59
60
const cartLength = computed (() => cart .cartQuantity );
60
61
const cartSubtotal = computed (() => cart .cartSubtotal );
61
-
62
- onMounted (async () => {
63
- try {
64
- await cart .refetch ();
65
- } catch (err) {
66
- error .value = err;
67
- } finally {
68
- isLoading .value = false ;
69
- }
70
- });
71
62
</script >
You can’t perform that action at this time.
0 commit comments