Skip to content

Commit

Permalink
switched to vue 3
Browse files Browse the repository at this point in the history
  • Loading branch information
atomjar committed May 14, 2020
1 parent 0ade166 commit 83ceaf0
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 36 deletions.
24 changes: 13 additions & 11 deletions components/ProductDisplay.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
Vue.component('product-display', {
app.component('product-display', {
props: {
premium: {
type: Boolean,
required: true,
},
required: true
}
},
template: `
template:
/*html*/
`
<div class="product">
<div class="container">
Expand Down Expand Up @@ -56,18 +58,18 @@ Vue.component('product-display', {
id: 2234,
color: 'green',
image: './assets/images/socks_green.jpg',
quantity: 10,
quantity: 10
},
{
id: 2235,
color: 'blue',
image: './assets/images/socks_blue.jpg',
quantity: 0,
},
quantity: 0
}
],
reviews: [],
tabs: ['review-form', 'review-list'],
activeTab: 'review-form',
activeTab: 'review-form'
}
},
methods: {
Expand All @@ -79,7 +81,7 @@ Vue.component('product-display', {
},
addReview(review) {
this.reviews.push(review)
},
}
},
computed: {
productName() {
Expand All @@ -96,6 +98,6 @@ Vue.component('product-display', {
return 'Free'
}
return 2.99
},
},
}
}
})
14 changes: 8 additions & 6 deletions components/ReviewForm.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Vue.component('review-form', {
template: `
app.component('review-form', {
template:
/*html*/
`
<form class="review-form" @submit.prevent="onSubmit">
<h3>Leave a review</h3>
Expand All @@ -26,20 +28,20 @@ Vue.component('review-form', {
return {
name: '',
text: '',
rating: null,
rating: null
}
},
methods: {
onSubmit() {
const review = {
name: this.name,
text: this.text,
rating: this.rating,
rating: this.rating
}
this.$emit('review-submitted', review)
this.name = ''
this.text = ''
this.rating = null
},
},
}
}
})
12 changes: 7 additions & 5 deletions components/ReviewList.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Vue.component('review-list', {
template: `
app.component('review-list', {
template:
/*html*/
`
<div class="review-container">
<p v-if="!reviews.length">There are no reviews yet.</p>
<ul v-else>
Expand All @@ -14,7 +16,7 @@ Vue.component('review-list', {
props: {
reviews: {
type: Array,
required: true,
},
},
required: true
}
}
})
12 changes: 5 additions & 7 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,9 @@
<!-- Import Styles -->
<link rel="stylesheet" href="./assets/styles.css" />
<!-- Import Vue.js -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://unpkg.com/vue@3.0.0-beta.12/dist/vue.global.js"></script>
</head>

<body>
<!-- Import Components -->
<script src="./components/ProductDisplay.js"></script>
<script src="./components/ReviewForm.js"></script>
<script src="./components/ReviewList.js"></script>

<div id="app">
<div class="nav-bar"></div>

Expand All @@ -29,5 +23,9 @@

<!-- Import App -->
<script src="./main.js"></script>
<!-- Import Components -->
<script src="./components/ProductDisplay.js"></script>
<script src="./components/ReviewForm.js"></script>
<script src="./components/ReviewList.js"></script>
</body>
</html>
17 changes: 10 additions & 7 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
const app = new Vue({
el: '#app',
data: {
premium: true,
cart: [],
const app = Vue.createApp({
data() {
return {
premium: true,
cart: []
}
},
methods: {
updateCart(id) {
this.cart.push(id)
},
},
}
}
})

app.mount('#app')

0 comments on commit 83ceaf0

Please sign in to comment.