Skip to content

Commit 1d1ce63

Browse files
committed
Simple product list
0 parents  commit 1d1ce63

12 files changed

+13267
-0
lines changed

.gitignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.DS_Store
2+
node_modules
3+
/dist
4+
5+
# local env files
6+
.env.local
7+
.env.*.local
8+
9+
# Log files
10+
npm-debug.log*
11+
yarn-debug.log*
12+
yarn-error.log*
13+
14+
# Editor directories and files
15+
.idea
16+
.vscode
17+
*.suo
18+
*.ntvs*
19+
*.njsproj
20+
*.sln
21+
*.sw*

babel.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
presets: [
3+
'@vue/app'
4+
]
5+
}

package-lock.json

Lines changed: 12988 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"name": "vue-app",
3+
"version": "0.1.0",
4+
"private": true,
5+
"scripts": {
6+
"serve": "vue-cli-service serve --open",
7+
"build": "vue-cli-service build",
8+
"lint": "vue-cli-service lint"
9+
},
10+
"dependencies": {
11+
"vee-validate": "^2.0.9",
12+
"vue": "^2.5.16"
13+
},
14+
"devDependencies": {
15+
"@vue/cli-plugin-babel": "^3.0.0-beta.11",
16+
"@vue/cli-plugin-eslint": "^3.0.0-beta.11",
17+
"@vue/cli-service": "^3.0.0-beta.11",
18+
"vue-template-compiler": "^2.5.16"
19+
},
20+
"eslintConfig": {
21+
"root": true,
22+
"env": {
23+
"node": true
24+
},
25+
"extends": [
26+
"plugin:vue/essential",
27+
"eslint:recommended"
28+
],
29+
"rules": {},
30+
"parserOptions": {
31+
"parser": "babel-eslint"
32+
}
33+
},
34+
"postcss": {
35+
"plugins": {
36+
"autoprefixer": {}
37+
}
38+
},
39+
"browserslist": [
40+
"> 1%",
41+
"last 2 versions",
42+
"not ie <= 8"
43+
]
44+
}

public/favicon.ico

1.12 KB
Binary file not shown.

public/index.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width,initial-scale=1.0">
7+
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
8+
<title>Simple vue-app</title>
9+
</head>
10+
11+
<body>
12+
<noscript>
13+
<strong>We're sorry but vue-app doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
14+
</noscript>
15+
16+
<div id="app"></div>
17+
18+
<!-- built files will be auto injected -->
19+
</body>
20+
</html>

src/App.vue

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<template>
2+
<div id="app">
3+
<img src="./assets/logo.png">
4+
5+
<ProductList msg="Product list injected from App.js" :products="products"/>
6+
7+
<add-product @onAddProduct="handleAddProduct"></add-product>
8+
</div>
9+
</template>
10+
11+
<script>
12+
import AddProduct from './components/AddProduct';
13+
import ProductList from './components/ProductList';
14+
import VeeValidate from 'vee-validate';
15+
import Vue from 'vue';
16+
17+
Vue.use(VeeValidate);
18+
19+
export default {
20+
name: 'app',
21+
components: {
22+
AddProduct,
23+
ProductList
24+
},
25+
data() {
26+
return {
27+
products: [{
28+
id: 0,
29+
name: 'Pizza'
30+
}, {
31+
id: 1,
32+
name: 'Burger'
33+
}, {
34+
id: 1,
35+
name: 'Orange juice'
36+
}]
37+
}
38+
},
39+
methods: {
40+
handleAddProduct(product) {
41+
this.products.push(product);
42+
}
43+
}
44+
}
45+
</script>
46+
47+
<style>
48+
#app {
49+
-moz-osx-font-smoothing: grayscale;
50+
-webkit-font-smoothing: antialiased;
51+
color: #2c3e50;
52+
font-family: 'Avenir', Helvetica, Arial, sans-serif;
53+
margin-top: 60px;
54+
text-align: center;
55+
}
56+
</style>

src/assets/logo.png

6.69 KB
Loading

src/components/AddProduct.vue

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<template>
2+
<form @submit.prevent="onSubmit()">
3+
<input name="product" v-model="newProduct.name" type="text" v-validate="'required|min:3'">
4+
5+
<button>Add hardcoded text</button>
6+
7+
<div v-show="errors.has('product')">
8+
{{ errors.first('product') }}
9+
</div>
10+
</form>
11+
</template>
12+
13+
14+
<script>
15+
export default {
16+
name: 'AddProduct',
17+
data() {
18+
return {
19+
newProduct: {
20+
name: ''
21+
}
22+
}
23+
},
24+
methods: {
25+
onSubmit() {
26+
this.$validator.validateAll().then(result => {
27+
if (!result) {
28+
return;
29+
}
30+
31+
this.$emit('onAddProduct', {
32+
id: Date.now(),
33+
...this.newProduct
34+
});
35+
36+
this.newProduct.name = '';
37+
this.$validator.reset();
38+
});
39+
}
40+
}
41+
}
42+
</script>
43+
44+
<style scoped>
45+
form {
46+
margin-top: 20px;
47+
}
48+
49+
form button {
50+
margin-left: 10px;
51+
}
52+
</style>

src/components/Product.vue

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<template>
2+
<li>{{ product.name }} <button v-on:click="removeCurrent(product)">Usuń</button></li>
3+
</template>
4+
5+
<script>
6+
export default {
7+
name: 'Product',
8+
props: {
9+
product: Object
10+
},
11+
methods: {
12+
removeCurrent(product) {
13+
this.$emit('onRemoveProduct', {
14+
id: product.id,
15+
});
16+
}
17+
}
18+
}
19+
</script>

src/components/ProductList.vue

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<template>
2+
<div>
3+
<h1>{{ msg }}</h1>
4+
5+
<ul v-if="products.length" class="list">
6+
<Product v-for="product in products" v-bind:product="product" @onRemoveProduct="handleRemoveProduct"/>
7+
</ul>
8+
9+
<p v-else>No products!</p>
10+
11+
<button v-on:click="removeLastItem()">Remove last item</button>
12+
<button v-on:click="sortList()">Sort products</button>
13+
</div>
14+
</template>
15+
16+
<script>
17+
import Product from './Product';
18+
19+
export default {
20+
name: 'ProductList',
21+
props: {
22+
msg: String,
23+
products: {
24+
type: Array,
25+
}
26+
},
27+
components: {
28+
Product
29+
},
30+
methods: {
31+
removeLastItem() {
32+
this.products.pop();
33+
},
34+
35+
handleRemoveProduct(id) {
36+
this.products.splice(this.products.indexOf(id), 1);
37+
},
38+
39+
sortList() {
40+
return this.products.sort((a, b) => a.name > b.name );
41+
}
42+
}
43+
}
44+
</script>
45+
46+
<style scoped>
47+
.list {
48+
list-style: none;
49+
}
50+
51+
button {
52+
margin: 0 5px;
53+
}
54+
</style>

src/main.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import Vue from 'vue'
2+
import App from './App.vue'
3+
4+
Vue.config.productionTip = false
5+
6+
new Vue({
7+
render: h => h(App)
8+
}).$mount('#app')

0 commit comments

Comments
 (0)