Compare commits

...

18 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
6 changed files with 122 additions and 198 deletions

View File

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

View File

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

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

@ -1,35 +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.0-beta.12/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="product-display">
<div class="product-container">
<div class="product-image">
<img v-bind:src="image">
</div>
<div class="product-info">
<h1>{{ product }}</h1>
</div>
</div>
</div>
</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>
<!-- Mount App -->
<script>
const mountedApp = app.mount('#app')
</script>
</body>
<!-- Import Components -->
<script src="./components/ProductDisplay.js"></script>
<!-- Mount App -->
<script>
const mountedApp = app.mount("#app");
</script>
</body>
</html>

19
main.js
View File

@ -1,8 +1,13 @@
const app = Vue.createApp({
data() {
return {
product: 'Socks',
image: './assets/images/socks_blue.jpg'
}
}
})
data() {
return {
cart: [],
premium: true,
};
},
methods: {
updateCart(id) {
this.cart.push(id);
},
},
});