File tree Expand file tree Collapse file tree 4 files changed +32
-21
lines changed
Expand file tree Collapse file tree 4 files changed +32
-21
lines changed Original file line number Diff line number Diff line change 6262
6363 export default {
6464 props: [' cart' ],
65- mixins: [ CartMixin ]
65+ mixins: [ CartMixin ],
66+ beforeRouteLeave (to , from , next ) {
67+ if (this .cart .items .length > 0 ) {
68+ if (! confirm (' Are you sure you don\' t want to buy these products?' )) {
69+ return next (false );
70+ }
71+ }
72+
73+ next ();
74+ }
6675 }
6776 </script >
Original file line number Diff line number Diff line change 2727 };
2828 },
2929 created () {
30- this .$watch (' $route.query.discount' , (newValue , oldValue ) => {
31- this .discount = this .getDiscount (this .product .price , newValue);
32- });
33-
3430 this .product = this .getProduct (this .productId );
3531
3632 if (typeof this .$route .query .discount !== ' undefined' ) {
3733 this .discount = this .getDiscount (this .product .price , this .$route .query .discount );
3834 }
3935 },
40- watch : {
41- productId ( newValue , oldValue ) {
42- this .product = this .getProduct (newValue );
43- this . discount = this . getDiscount ( this . product . price , this . $route . query . discount );
44- }
36+ beforeRouteUpdate ( to , from , next ) {
37+ this . discount = this . getDiscount ( this . product . price , to . query . discount );
38+ this .product = this .getProduct (to . params . productId );
39+
40+ next ();
4541 },
4642 methods: {
4743 getProduct (productId ) {
Original file line number Diff line number Diff line change 11<template >
22 <h1 >My Profile</h1 >
3- </template >
3+ </template >
4+
5+ <script >
6+ import { authService } from ' ./main' ;
7+
8+ export default {
9+ beforeRouteEnter (to , from , next ) {
10+ if (! authService .isLoggedIn ) {
11+ alert (" You must be logged in!" );
12+ return next (false );
13+ }
14+
15+ next ();
16+ }
17+ }
18+ </script >
Original file line number Diff line number Diff line change @@ -5,7 +5,6 @@ import Product from './Product.vue';
55import ProductReviews from './ProductReviews.vue' ;
66import SpecialOffer from './SpecialOffer.vue' ;
77import ViewProfile from './ViewProfile.vue' ;
8- import { authService } from './main' ;
98
109export const routes = [
1110 { path : '' , components : {
@@ -19,15 +18,7 @@ export const routes = [
1918 {
2019 path : '/user/profile' ,
2120 name : 'viewProfile' ,
22- component : ViewProfile ,
23- beforeEnter ( to , from , next ) {
24- if ( ! authService . isLoggedIn ) {
25- alert ( "You must be logged in!" ) ;
26- return next ( false ) ;
27- }
28-
29- next ( ) ;
30- }
21+ component : ViewProfile
3122 } ,
3223 { path : '/cart' , component : Cart } ,
3324 { path : '*' , component : { template : '<h1>Page Not Found!</h1>' } }
You can’t perform that action at this time.
0 commit comments