Compare commits

...

23 Commits

Author SHA1 Message Date
bwbl
3251d861fc WIP L10.4 2026-01-13 16:27:46 +01:00
Andy
6253c36939 update cdn link 2021-04-09 16:03:50 -04:00
Andy
3cfcc7cbdd L10 starting 2020-07-29 19:18:33 -04:00
Adam Jahr
1a8cd4892b L10 starting 2020-07-21 01:16:26 -04:00
Adam Jahr
8c51141d99 L10 starting code 2020-07-21 00:50:20 -04:00
Adam Jahr
e5a0b6e460 L9 solution 2020-07-21 00:48:15 -04:00
Adam Jahr
40c519c162 L10 ending code 2020-07-08 22:59:10 -04:00
Adam Jahr
ac72852668 L9 starting code 2020-07-07 21:42:47 -04:00
Adam Jahr
d440ca92fb L8 ending code 2020-07-06 22:28:50 -04:00
Adam Jahr
58e74974e0 L7 starting code 2020-07-06 21:58:48 -04:00
Adam Jahr
44d8427b7a L7 starting code 2020-07-06 21:41:58 -04:00
Adam Jahr
33ef706431 L7 starting code 2020-07-06 21:39:31 -04:00
Adam Jahr
7f52372b6c L6 ending code 2020-06-24 01:48:12 -04:00
Adam Jahr
2bd501d071 L5 ending code 2020-06-19 19:45:00 -04:00
Adam Jahr
a6209b82c8 L5 starting code 2020-06-19 19:41:08 -04:00
Adam Jahr
9ce75d24c2 L5 ending code 2020-06-19 19:36:48 -04:00
Adam Jahr
a903dd19cb L5 starting code 2020-06-19 17:23:40 -04:00
Adam Jahr
2846669a3f L4 ending code 2020-06-02 21:21:37 -04:00
Adam Jahr
b92a6c065c L4 starting code 2020-06-02 20:33:19 -04:00
Adam Jahr
0f08a0ddb3 L3 ending code 2020-05-29 22:12:52 -04:00
Adam Jahr
7db826380e L3 starting code 2020-05-29 22:04:13 -04:00
Adam Jahr
95bb5ecd55 L3 start 2020-05-26 23:45:05 -04:00
Adam Jahr
39452ddc6c lesson 3 ending 2020-05-26 23:39:42 -04:00
6 changed files with 124 additions and 177 deletions

View File

@ -25,7 +25,7 @@ body {
margin: 25px 100px; margin: 25px 100px;
float: right; float: right;
border: 1px solid #d8d8d8; border: 1px solid #d8d8d8;
padding: 10px 30px; padding: 30px 30px;
background-color: white; background-color: white;
-webkit-box-shadow: 0px 2px 15px -12px rgba(0, 0, 0, 0.57); -webkit-box-shadow: 0px 2px 15px -12px rgba(0, 0, 0, 0.57);
-moz-box-shadow: 0px 2px 15px -12px rgba(0, 0, 0, 0.57); -moz-box-shadow: 0px 2px 15px -12px rgba(0, 0, 0, 0.57);
@ -88,6 +88,10 @@ li {
box-shadow: 1px 1px 5px rgba(0, 0, 0, 0.57); box-shadow: 1px 1px 5px rgba(0, 0, 0, 0.57);
} }
.out-of-stock-img {
opacity: 0.5;
}
p { p {
font-size: 22px; font-size: 22px;
} }

View File

@ -1,102 +1,93 @@
app.component('product-display', { app.component("product-display", {
props: { props: {
premium: { premium: {
type: Boolean, type: Boolean,
required: true required: true,
} },
}, },
template: template:
/*html*/ /*html*/
` `<div class="product-display">
<div class="product-display">
<div class="product-container"> <div class="product-container">
<div class="product-image"> <div class="product-image">
<img :src="image" /> <img v-bind:src="image">
</div> </div>
<div class="product-info"> <div class="product-info">
<h1>{{ productName }}</h1> <h1>{{ title }}</h1>
<p v-if="inStock">In Stock</p> <p v-if="inStock">In Stock</p>
<p v-else>Out of Stock</p> <p v-else>Out of Stock</p>
<p>Shipping: {{ shipping }}</p> <p>Shipping: {{ shipping }}</p>
<ul> <ul>
<li v-for="detail in details">{{ detail }}</li> <li v-for="detail in details">{{ detail }}</li>
</ul> </ul>
<div class="color-circle" <div
v-for="(variant, index) in variants" v-for="(variant, index) in variants"
:key="variant.id" :key="variant.id"
:style="{ backgroundColor: variant.color }" @mouseover="updateVariant(index)"
@mouseover="updateProduct(index)" class="color-circle"
> :style="{ backgroundColor: variant.color }">
</div> </div>
<button class="button" v-on:click="addToCart" <button
:disabled="!inStock" class="button"
:class="{ disabledButton: !inStock }" :class="{ disabledButton: !inStock }"
> :disabled="!inStock"
Add to cart v-on:click="addToCart">
Add to Cart
</button> </button>
</div> </div>
</div> </div>
</div>`,
<review-list :reviews="reviews"></review-list>
<review-form @review-submitted="addReview" ></review-form>
</div>
`,
data() { data() {
return { return {
product: 'Socks', product: "Socks",
brand: 'Vue Mastery', brand: "Vue Mastery",
selectedVariant: 0, selectedVariant: 0,
details: ['80% cotton', '20% polyester', 'Gender-neutral'], details: ["50% cotton", "30% wool", "20% polyester"],
variants: [ variants: [
{ {
id: 2234, id: 2234,
color: 'green', color: "green",
image: './assets/images/socks_green.jpg', image: "./assets/images/socks_green.jpg",
quantity: 10 quantity: 50,
}, },
{ {
id: 2235, id: 2235,
color: 'blue', color: "blue",
image: './assets/images/socks_blue.jpg', image: "./assets/images/socks_blue.jpg",
quantity: 0 quantity: 0,
} },
], ],
reviews: [], };
tabs: ['review-form', 'review-list'],
activeTab: 'review-form'
}
}, },
methods: { methods: {
addToCart() { addToCart() {
this.$emit('add-to-cart', this.variants[this.selectedVariant].id) this.$emit("add-to-cart", this.variants[this.selectedVariant].id);
this.cart += 1;
}, },
updateProduct(index) { updateVariant(index) {
this.selectedVariant = index this.selectedVariant = index;
}, },
addReview(review) {
this.reviews.push(review)
}
}, },
computed: { computed: {
productName() { title() {
return this.brand + ' ' + this.product return this.brand + " " + this.product;
}, },
image() { image() {
return this.variants[this.selectedVariant].image return this.variants[this.selectedVariant].image;
}, },
inStock() { inStock() {
return this.variants[this.selectedVariant].quantity return this.variants[this.selectedVariant].quantity;
}, },
shipping() { shipping() {
if (this.premium) { if (this.premium) {
return 'Free' return "Free";
} }
return 2.99 return 2.99;
} },
} },
}) });

View File

@ -1,52 +0,0 @@
app.component('review-form', {
template:
/*html*/
`
<form class="review-form" @submit.prevent="onSubmit">
<h3>Leave a review</h3>
<label for="name">Name:</label>
<input id="name" v-model="name">
<label for="review">Review:</label>
<textarea id="review" v-model="text"></textarea>
<label for="rating">Rating:</label>
<select id="rating" v-model.number="rating">
<option>5</option>
<option>4</option>
<option>3</option>
<option>2</option>
<option>1</option>
</select>
<input class="button" type="submit" value="Submit">
</form>
`,
data() {
return {
name: '',
text: '',
rating: null
}
},
methods: {
onSubmit() {
if (this.name === '' || this.text === '' || this.rating === null) {
alert('Review is incomplete. Please fill out every field.')
return
}
const review = {
name: this.name,
text: this.text,
rating: this.rating
}
this.$emit('review-submitted', review)
this.name = ''
this.text = ''
this.rating = null
}
}
})

View File

@ -1,22 +0,0 @@
app.component('review-list', {
template:
/*html*/
`
<div v-if="reviews.length" class="review-container">
<h3>Reviews:</h3>
<ul>
<li v-for="(review, index) in reviews" :key="index">
{{ review.name }} gave this {{ review.rating }} stars
<br/>
"{{ review.text }}"
</li>
</ul>
</div>
`,
props: {
reviews: {
type: Array,
required: true
}
}
})

View File

@ -6,14 +6,28 @@
<!-- Import Styles --> <!-- Import Styles -->
<link rel="stylesheet" href="./assets/styles.css" /> <link rel="stylesheet" href="./assets/styles.css" />
<!-- Import Vue.js --> <!-- Import Vue.js -->
<script src="https://unpkg.com/vue@3.0.0-beta.12/dist/vue.global.js"></script> <script src="https://unpkg.com/vue@3.0.11/dist/vue.global.js"></script>
</head> </head>
<body> <body>
<div id="app"> <div id="app">
<h1>Product goes here</h1> <div class="nav-bar"></div>
<div class="cart">Cart({{ cart.length }})</div>
<product-display
:premium="premium"
@add-to-cart="updateCart"
></product-display>
</div> </div>
<!-- Import JS --> <!-- Import App -->
<script src="./main.js"></script> <script src="./main.js"></script>
<!-- Import Components -->
<script src="./components/ProductDisplay.js"></script>
<!-- Mount App -->
<script>
const mountedApp = app.mount("#app");
</script>
</body> </body>
</html> </html>

14
main.js
View File

@ -1 +1,13 @@
const product = "Socks" const app = Vue.createApp({
data() {
return {
cart: [],
premium: true,
};
},
methods: {
updateCart(id) {
this.cart.push(id);
},
},
});