Vue cart
How do I make an vue cart?
Vue shopping-cart. What is a vue cart? How do you make a vue cart? This script and codes were developed by Dima on 26 September 2022, Monday.
Vue cart - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>vue cart</title> <link rel="stylesheet" href="css/style.css">
</head>
<body>
<div id="vue"> <div class="flex" id="shop"> <div class="item" v-for="product in products"><img :src="'//zupra.github.io/t-shirt_shop/img/test-2/'+product.id+'.png'"/> <div class="name">{{ product.name }}</div> <div class="price">{{ product.price }} ₽</div> <button class="btn" :disabled="product.qty" @click="addToCart(product)"> <template v-if="!product.qty">Add to Cart </template> <template v-else="v-else">✔ in Cart <b>{{product.qty}}</b></template> </button> </div> </div> <div id="cart"> <h1>cart </h1> <h2>{{count}} / {{total}} ₽</h2> <div class="cart_item" v-for="item,i in cart" v-if="item.qty > 0"><b>{{ item.qty }}</b> × {{ item.name }} {{ item.price }} <button @click="item.qty += 1">+1</button> <button v-if="item.qty > 1" @click="(item.qty > 1) ? item.qty -= 1 : ''">-1</button> <button @click="del(i, item.id)">X</button> </div> </div>
</div> <script src='https://cdnjs.cloudflare.com/ajax/libs/vue/2.1.10/vue.js'></script> <script src="js/index.js"></script>
</body>
</html>
Vue cart - Script Codes CSS Codes
* { margin: 0; padding: 0; box-sizing: border-box;
}
body { font-family: sans-serif; color: #262626;
}
.flex { display: -webkit-box; display: -ms-flexbox; display: flex; -ms-flex-pack: distribute; justify-content: space-around;
}
#shop { margin: 1em 270px 1em 1em; -ms-flex-wrap: wrap; flex-wrap: wrap;
}
#shop .item { text-align: center;
}
#shop .name { margin-bottom: 0.5em;
}
#shop .price { color: #000; font-size: 1.2em; display: inline-block; background: #fffbd3; padding: 0.5em; border-radius: 0.5em; vertical-align: middle;
}
#cart { border-left: 1px solid #eee; position: fixed; margin: 1em 0 0; top: 0; right: 0; width: 270px; padding: 0.5em 1em 2em;
}
#cart h1,
#cart h2 { text-align: center;
}
#cart .cart_item { padding: 0.5em 0; border-bottom: 1px dashed #ccc;
}
button { vertical-align: middle; outline: 0; border: 0; cursor: pointer; padding: 0.5em 1em; border-radius: 5px; border-bottom: 3px solid rgba(0,0,0,0.3); background: #e0e4cc;
}
button:hover { background: #e9ecdb;
}
.btn { background: #ffe766; font-size: 1em;
}
.btn:hover { background: #ffd700;
}
.btn[disabled] { cursor: default; background: #f0f2e6;
}
Vue cart - Script Codes JS Codes
"use strict";
var vm = new Vue({ el: "#vue", data: { products: [{ id: 1, name: "black", price: 99 }, { id: 2, name: "dark-blue", price: 99 }, { id: 3, name: "green", price: 99 }, { id: 4, name: "grey", price: 99 }, { id: 5, name: "light-blue", price: 99 }, { id: 6, name: "pink", price: 99 }, { id: 7, name: "purple", price: 99 }, { id: 8, name: "red", price: 99 }, { id: 9, name: "white", price: 99 }], cart: [] }, computed: { count: function count() { return this.cart.reduce(function (n, cart) { return cart.qty + n; }, 0); }, total: function total() { return this.cart.reduce(function (n, cart) { return cart.price * cart.qty + n; }, 0).toFixed(2); } }, methods: { addToCart: function addToCart(product) { this.$set(product, 'qty', +1); this.cart.push(product); }, unblock: function unblock(id) { for (var i = 0; i < this.products.length; i++) { if (this.products[i].id === id) { delete this.products[i].qty; break; } } }, del: function del(index, id) { this.cart.splice(index, 1); this.unblock(id); } }
});
Developer | Dima |
Username | dimaZubkov |
Uploaded | September 26, 2022 |
Rating | 3 |
Size | 4,497 Kb |
Views | 30,360 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
A Pen by Dima | 3,031 Kb |
Three js | 2,323 Kb |
Ken Burns effect CSS only | 3,398 Kb |
Glitch | 2,843 Kb |
Ken Burns Effect | 3,067 Kb |
Vue radio | 5,915 Kb |
Css masonry | 3,130 Kb |
Angular T-shirt shop | 8,889 Kb |
Responsive typography harmony | 4,090 Kb |
Star Rating | 2,819 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
CSS- UI Element States Pseudo-Classes | Tesla809 | 2,206 Kb |
Particle Motion trajectories | Sniejadlik | 5,899 Kb |
Fixed with using Calc | Tomleo | 2,542 Kb |
Profile box | Daniesy | 2,766 Kb |
Transitioning application screens with semantically named classes | Djgrant | 3,697 Kb |
Impress JS Algorhytmic Generator | Jeffscottward | 7,906 Kb |
Pure CSS Tooltip | APinix | 2,815 Kb |
Two column of responsive height | Fixie | 2,908 Kb |
Svg sky | Omodev | 7,070 Kb |
Compare resources on mobile sites | Gyusza | 3,226 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!