Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3251d861fc | ||
|
|
6253c36939 | ||
|
|
3cfcc7cbdd | ||
|
|
1a8cd4892b | ||
|
|
8c51141d99 | ||
|
|
e5a0b6e460 | ||
|
|
40c519c162 | ||
|
|
ac72852668 | ||
|
|
d440ca92fb | ||
|
|
58e74974e0 | ||
|
|
44d8427b7a | ||
|
|
33ef706431 | ||
|
|
7f52372b6c | ||
|
|
2bd501d071 |
@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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>
|
data() {
|
||||||
<review-form @review-submitted="addReview" ></review-form>
|
return {
|
||||||
</div>
|
product: "Socks",
|
||||||
`,
|
brand: "Vue Mastery",
|
||||||
data() {
|
selectedVariant: 0,
|
||||||
return {
|
details: ["50% cotton", "30% wool", "20% polyester"],
|
||||||
product: 'Socks',
|
variants: [
|
||||||
brand: 'Vue Mastery',
|
{
|
||||||
selectedVariant: 0,
|
id: 2234,
|
||||||
details: ['80% cotton', '20% polyester', 'Gender-neutral'],
|
color: "green",
|
||||||
variants: [
|
image: "./assets/images/socks_green.jpg",
|
||||||
{
|
quantity: 50,
|
||||||
id: 2234,
|
},
|
||||||
color: 'green',
|
{
|
||||||
image: './assets/images/socks_green.jpg',
|
id: 2235,
|
||||||
quantity: 10
|
color: "blue",
|
||||||
},
|
image: "./assets/images/socks_blue.jpg",
|
||||||
{
|
quantity: 0,
|
||||||
id: 2235,
|
},
|
||||||
color: 'blue',
|
],
|
||||||
image: './assets/images/socks_blue.jpg',
|
};
|
||||||
quantity: 0
|
},
|
||||||
}
|
methods: {
|
||||||
],
|
addToCart() {
|
||||||
reviews: [],
|
this.$emit("add-to-cart", this.variants[this.selectedVariant].id);
|
||||||
tabs: ['review-form', 'review-list'],
|
this.cart += 1;
|
||||||
activeTab: 'review-form'
|
},
|
||||||
}
|
updateVariant(index) {
|
||||||
},
|
this.selectedVariant = index;
|
||||||
methods: {
|
},
|
||||||
addToCart() {
|
},
|
||||||
this.$emit('add-to-cart', this.variants[this.selectedVariant].id)
|
computed: {
|
||||||
},
|
title() {
|
||||||
updateProduct(index) {
|
return this.brand + " " + this.product;
|
||||||
this.selectedVariant = index
|
},
|
||||||
},
|
image() {
|
||||||
addReview(review) {
|
return this.variants[this.selectedVariant].image;
|
||||||
this.reviews.push(review)
|
},
|
||||||
}
|
inStock() {
|
||||||
},
|
return this.variants[this.selectedVariant].quantity;
|
||||||
computed: {
|
},
|
||||||
productName() {
|
shipping() {
|
||||||
return this.brand + ' ' + this.product
|
if (this.premium) {
|
||||||
},
|
return "Free";
|
||||||
image() {
|
}
|
||||||
return this.variants[this.selectedVariant].image
|
return 2.99;
|
||||||
},
|
},
|
||||||
inStock() {
|
},
|
||||||
return this.variants[this.selectedVariant].quantity
|
});
|
||||||
},
|
|
||||||
shipping() {
|
|
||||||
if (this.premium) {
|
|
||||||
return 'Free'
|
|
||||||
}
|
|
||||||
return 2.99
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|||||||
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
58
index.html
58
index.html
@ -1,37 +1,33 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<title>Vue Mastery</title>
|
<title>Vue Mastery</title>
|
||||||
<!-- 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">
|
||||||
<div class="nav-bar"></div>
|
<div class="nav-bar"></div>
|
||||||
|
|
||||||
<div class="product-display">
|
<div class="cart">Cart({{ cart.length }})</div>
|
||||||
<div class="product-container">
|
<product-display
|
||||||
<div class="product-image">
|
:premium="premium"
|
||||||
<img v-bind:src="image">
|
@add-to-cart="updateCart"
|
||||||
</div>
|
></product-display>
|
||||||
<div class="product-info">
|
</div>
|
||||||
<h1>{{ product }}</h1>
|
|
||||||
<p v-if="inStock">In Stock</p>
|
|
||||||
<p v-else>Out of Stock</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Import App -->
|
<!-- Import App -->
|
||||||
<script src="./main.js"></script>
|
<script src="./main.js"></script>
|
||||||
|
|
||||||
<!-- Mount App -->
|
<!-- Import Components -->
|
||||||
<script>
|
<script src="./components/ProductDisplay.js"></script>
|
||||||
const mountedApp = app.mount('#app')
|
|
||||||
</script>
|
<!-- Mount App -->
|
||||||
</body>
|
<script>
|
||||||
|
const mountedApp = app.mount("#app");
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
21
main.js
21
main.js
@ -1,10 +1,13 @@
|
|||||||
const app = Vue.createApp({
|
const app = Vue.createApp({
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
product: 'Socks',
|
cart: [],
|
||||||
image: './assets/images/socks_blue.jpg',
|
premium: true,
|
||||||
inStock: true,
|
};
|
||||||
details: ['50% cotton', '30% wool', '20% polyester']
|
},
|
||||||
}
|
methods: {
|
||||||
}
|
updateCart(id) {
|
||||||
})
|
this.cart.push(id);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user