Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

              <div id="app" class="container">
   <div class="text-right"><button class="btn btn-primary" data-toggle="modal" data-target="#cartModal">Cart ({{cartItems.length}})</button></div>
   <!-- Modal --> 
   <div class="modal fade" id="cartModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
      <div class="modal-dialog" role="document">
         <div class="modal-content">
            <div class="modal-header">
               <button type="button" class="close" data-dismiss="modal" aria-label="Close">          <span aria-hidden="true">&times;</span></button>
               <h4 class="modal-title" id="myModalLabel">Cart</h4>
            <div class="modal-body">
               <shopping-cart inline-template :items="cartItems">
                     <table class="table table-cart">
                        <tr v-for="(item, index) in items">
                           <td style="width:120px">QTY:
                              <input v-model="item.qty" class="form-control input-qty" type="number">
                           <td class="text-right">${{item.price | formatCurrency}}</td>
                              <button @click="removeItem(index)"><span class="glyphicon glyphicon-trash"></span></button>
                        <tr v-show="items.length === 0">
                           <td colspan="4" class="text-center">Cart is empty</td>
                        <tr v-show="items.length > 0">
                           <td class="text-right">Cart Total</td>
                           <td class="text-right">${{Total | formatCurrency}}</td>
                  <!-- /.container -->
            <div class="modal-footer">
               <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
   <div class="container">
      <div class="row">
         <div class="col-xs-3 text-center" v-for="item in items">
            <img class="img-responsive" :src="item.image" alt="">
            <h5>{{ item.title }}</h5>
            <h6>${{ item.price | formatCurrency }}</h6>
            <p class="text-center"><input v-model="item.qty" type="number" class="form-control" placeholder="Qty" min="1"/></p>
               <button @click="addToCart(item)" class="btn btn-sm btn-primary">Add to Cart</button>

.input-qty {
  width: 60px;
  float: right

.table-cart > tr > td {
  vertical-align: middle !important;

              const products = [
	{id: 1,title: 'Macbook Pro', price: 2500.00, qty: 1, image: ''},  
	{id: 2,title: 'Asus ROG Gaming',price: 1000.00, qty: 1,image: ''},  
	{id: 3,title: 'Amazon Kindle',price: 150.00,qty: 1,image: ''},  
	{id: 4,title: 'Another Product',price: 10, qty: 1, image: ''},  

function formatNumber(n, c, d, t){
	var c = isNaN(c = Math.abs(c)) ? 2 : c, 
			d = d === undefined ? '.' : d, 
			t = t === undefined ? ',' : t, 
			s = n < 0 ? '-' : '', 
			i = String(parseInt(n = Math.abs(Number(n) || 0).toFixed(c))), 
			j = (j = i.length) > 3 ? j % 3 : 0;
	return s + (j ? i.substr(0, j) + t : '') + i.substr(j).replace(/(\d{3})(?=\d)/g, '$1' + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : '');

// Allow the formatNumber function to be used as a filter
Vue.filter('formatCurrency', function (value) {
	return formatNumber(value, 2, '.', ',');

// The shopping cart component
Vue.component('shopping-cart', {
  props: ['items'],

  computed: {
    Total() {
      let total = 0;
      this.items.forEach(item => {
        total += (item.price * item.qty);
      return total;

  methods: {
		// Remove item by its index
    removeItem(index) {
      this.items.splice(index, 1)

const vm = new Vue({
  el: '#app',
  data: {
    cartItems: [],
    items : products
  methods: {
		// Add Items to cart
    addToCart(itemToAdd) {
      let found = false;

      // Add the item or increase qty
			let itemInCart = this.cartItems.filter(item =>;
			let isItemInCart = itemInCart.length > 0;

      if (isItemInCart === false) {
        this.cartItems.push(Vue.util.extend({}, itemToAdd));
      } else {
				itemInCart[0].qty += itemToAdd.qty;
			itemToAdd.qty = 1;

🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.