main.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. const DISABLED = "disabledButton";
  2. const app = new Vue({
  3. el: "#app",
  4. data: {
  5. cart: 0,
  6. description: "Chaussettes montantes",
  7. details: [
  8. "80% cotton",
  9. "20% polyester",
  10. "Gender-neutral",
  11. ],
  12. image: "./assets/img/vmSocks-green-onWhite.jpg",
  13. inventory: 15,
  14. link: "https://www.google.com/search?q=vuejs+socks",
  15. onSale: false,
  16. product: "Socks",
  17. sizes: [32, 34, 36, 38, 40, 42, 44, 46, 48],
  18. variants: [
  19. { variantId: 2234, variantColor: "green", variantImage: "./assets/img/vmSocks-green-onWhite.jpg", },
  20. { variantId: 2235, variantColor: "blue", variantImage: "./assets/img/vmSocks-blue-onWhite.png", },
  21. ]
  22. },
  23. methods: {
  24. addToCart(mouseEvent) {
  25. const target = mouseEvent.target;
  26. if (this.inventory <= 0) {
  27. if (this.inventory < 0) {
  28. this.inventory = 0;
  29. }
  30. return;
  31. }
  32. this.inventory--;
  33. this.cart++;
  34. if (this.inventory <= 0) {
  35. this.inventory = 0;
  36. }
  37. },
  38. removeFromCart(mouseEvent) {
  39. const target = mouseEvent.target;
  40. if (this.cart <= 0) {
  41. if (this.cart < 0) {
  42. this.cart = 0;
  43. }
  44. }
  45. this.inventory++;
  46. this.cart--;
  47. if (this.cart <= 0) {
  48. this.cart = 0;
  49. }
  50. },
  51. updateImage(imageSrc) {
  52. this.image = imageSrc;
  53. }
  54. },
  55. });