-
Notifications
You must be signed in to change notification settings - Fork 0
/
index2.html
72 lines (65 loc) · 2.66 KB
/
index2.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<!-- development version, includes helpful console warnings -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id="app">
<h5>List of Products</h5>
<h3>Filter</h3>
<select v-model='category'>
<option valeu="Accessories">Accessories</option>
<option valeu="Laptop">Laptop</option>
<option valeu="Stationary">Stationary</option>
</select>
<input type="text" v-model="name" placeholder="Filter by name"/>
<label for="vol">Price(between 0 and 1000)</label>
<input type='range' v-model="range" min="0" max="1000" step="10"/>
<ul>
<li v-for="product in filterProducts">Product Name: {{product.name}}- price: {{product.price}} ({{product.category}})
</li>
</ul>
</div>
</body>
<script type="text/javascript">
var app = new Vue ({
el:"#app",
data:{
category:"",
name:"",
range:"500",
products: [
{ name: "Keyboard", price: 44, category: 'Accessories'},
{ name: "Mouse", price: 20, category: 'Accessories'},
{ name: "Monitor", price: 399, category: 'Accessories'},
{ name: "Dell XPS", price: 599, category: 'Laptop'},
{ name: "MacBook Pro", price: 899, category: 'Laptop'},
{ name: "Pencil Box", price: 6, category: 'Stationary'},
{ name: "Pen", price: 2, category: 'Stationary'},
{ name: "USB Cable", price: 7, category: 'Accessories'},
{ name: "Eraser", price: 2, category: 'Stationary'},
{ name: "Highlighter", price: 5, category: 'Stationary'}
]
},
computed:{
filterProducts: function(){
return this.filterProductsByRange(this.filterProductsByName(this.filterProductsByCategory(this.products)))
}
},
methods:{
filterProductsByCategory: function(products){
return products.filter(product => !product.category.indexOf(this.category))
},
filterProductsByName: function(products){
return products.filter(product => !product.name.indexOf(this.name))
},
filterProductsByRange: function(products){
return products.filter(product => (product.price>0 && product.price<this.range)? product: "")
}
},
})
</script>