WIP L10.4
This commit is contained in:
parent
6253c36939
commit
3251d861fc
@ -1,13 +1,13 @@
|
||||
app.component('product-display', {
|
||||
props: {
|
||||
premium: {
|
||||
type: Boolean,
|
||||
required: true
|
||||
}
|
||||
},
|
||||
template:
|
||||
/*html*/
|
||||
`<div class="product-display">
|
||||
app.component("product-display", {
|
||||
props: {
|
||||
premium: {
|
||||
type: Boolean,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
template:
|
||||
/*html*/
|
||||
`<div class="product-display">
|
||||
<div class="product-container">
|
||||
<div class="product-image">
|
||||
<img v-bind:src="image">
|
||||
@ -42,41 +42,52 @@ app.component('product-display', {
|
||||
</div>
|
||||
</div>
|
||||
</div>`,
|
||||
data() {
|
||||
return {
|
||||
product: 'Socks',
|
||||
brand: 'Vue Mastery',
|
||||
selectedVariant: 0,
|
||||
details: ['50% cotton', '30% wool', '20% polyester'],
|
||||
variants: [
|
||||
{ id: 2234, color: 'green', image: './assets/images/socks_green.jpg', quantity: 50 },
|
||||
{ id: 2235, color: 'blue', image: './assets/images/socks_blue.jpg', quantity: 0 },
|
||||
]
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
addToCart() {
|
||||
this.cart += 1
|
||||
},
|
||||
updateVariant(index) {
|
||||
this.selectedVariant = index
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
title() {
|
||||
return this.brand + ' ' + this.product
|
||||
},
|
||||
image() {
|
||||
return this.variants[this.selectedVariant].image
|
||||
},
|
||||
inStock() {
|
||||
return this.variants[this.selectedVariant].quantity
|
||||
},
|
||||
shipping() {
|
||||
if (this.premium) {
|
||||
return 'Free'
|
||||
}
|
||||
return 2.99
|
||||
}
|
||||
}
|
||||
})
|
||||
data() {
|
||||
return {
|
||||
product: "Socks",
|
||||
brand: "Vue Mastery",
|
||||
selectedVariant: 0,
|
||||
details: ["50% cotton", "30% wool", "20% polyester"],
|
||||
variants: [
|
||||
{
|
||||
id: 2234,
|
||||
color: "green",
|
||||
image: "./assets/images/socks_green.jpg",
|
||||
quantity: 50,
|
||||
},
|
||||
{
|
||||
id: 2235,
|
||||
color: "blue",
|
||||
image: "./assets/images/socks_blue.jpg",
|
||||
quantity: 0,
|
||||
},
|
||||
],
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
addToCart() {
|
||||
this.$emit("add-to-cart", this.variants[this.selectedVariant].id);
|
||||
this.cart += 1;
|
||||
},
|
||||
updateVariant(index) {
|
||||
this.selectedVariant = index;
|
||||
},
|
||||
},
|
||||
computed: {
|
||||
title() {
|
||||
return this.brand + " " + this.product;
|
||||
},
|
||||
image() {
|
||||
return this.variants[this.selectedVariant].image;
|
||||
},
|
||||
inStock() {
|
||||
return this.variants[this.selectedVariant].quantity;
|
||||
},
|
||||
shipping() {
|
||||
if (this.premium) {
|
||||
return "Free";
|
||||
}
|
||||
return 2.99;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
49
index.html
49
index.html
@ -1,30 +1,33 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>Vue Mastery</title>
|
||||
<!-- Import Styles -->
|
||||
<link rel="stylesheet" href="./assets/styles.css" />
|
||||
<!-- Import Vue.js -->
|
||||
<script src="https://unpkg.com/vue@3.0.11/dist/vue.global.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app">
|
||||
<div class="nav-bar"></div>
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>Vue Mastery</title>
|
||||
<!-- Import Styles -->
|
||||
<link rel="stylesheet" href="./assets/styles.css" />
|
||||
<!-- Import Vue.js -->
|
||||
<script src="https://unpkg.com/vue@3.0.11/dist/vue.global.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app">
|
||||
<div class="nav-bar"></div>
|
||||
|
||||
<div class="cart">Cart({{ cart }})</div>
|
||||
<product-display :premium="premium"></product-display>
|
||||
</div>
|
||||
<div class="cart">Cart({{ cart.length }})</div>
|
||||
<product-display
|
||||
:premium="premium"
|
||||
@add-to-cart="updateCart"
|
||||
></product-display>
|
||||
</div>
|
||||
|
||||
<!-- Import App -->
|
||||
<script src="./main.js"></script>
|
||||
<!-- Import App -->
|
||||
<script src="./main.js"></script>
|
||||
|
||||
<!-- Import Components -->
|
||||
<script src="./components/ProductDisplay.js"></script>
|
||||
<!-- Import Components -->
|
||||
<script src="./components/ProductDisplay.js"></script>
|
||||
|
||||
<!-- Mount App -->
|
||||
<script>
|
||||
const mountedApp = app.mount('#app')
|
||||
</script>
|
||||
</body>
|
||||
<!-- Mount App -->
|
||||
<script>
|
||||
const mountedApp = app.mount("#app");
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user