Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="task">
	<p>В приложении намерено допущена ошибка.</p>
	<p>Сейчас калькулятор считает всё правильно, но как только калькулятор создаётся нет значений начального количества товара и суммы</p>
	<p>Это должно выглядеть вот так <button>-</button> <b>0</b> <button>+</button> <b>0 руб.</b></p>
	<p>Эту проблему нужно решить двумя разными способами</p>
</div>

<div id="app">
	<list></list>
</div>
<template id="list">
	<div>
		<p v-for="(el, i) in list" :key="i">
			{{el.name}} - <small>{{el.price}}руб.</small> <button @click="minus(el.price, i)">-</button> <b>{{el.count}}</b> <button @click="plus(el.price, i)">+</button> <b>{{el.sum}} руб.</b>
		</p>
		<br>
		<b>Всего: {{total}} руб.</b>
	</div>
</template>
              
            
!

CSS

              
                .danger
	padding 5px
	background-color tomato
	color #FFF
.task
	padding 15px
	border 1px solid tomato
	p
		margin-top 0
		margin-bottom 0
		line-height 1.3
              
            
!

JS

              
                let list =  [{'name': 'товар 1', 'price': 50}, {'name': 'товар 2', 'price': 100}];
Vue.component('list',{
	template: '#list',
	data() {
		return {
			list,
			total: 0
		};
	},
	mounted() {
		this.list.forEach(function(el) {
			el.count = 0;
			el.sum = 0;
		});
	},
	methods: {
		plus(price, item) {
			this.total += price;
			this.list[item].sum += this.list[item].price;
			this.list[item].count += 1;
		},
		minus(price, item) {
			this.total -= price;
			if (this.total < 0) {
				this.total = 0
			}
			this.list[item].sum -= price;
			if (this.list[item].sum < 0) {
				this.list[item].sum = 0;
			}
			this.list[item].count -= 1;
			if (this.list[item].count < 0) {
				this.list[item].count = 0;
			}
		}
	}
})
new Vue({
	el: '#app'
})

              
            
!
999px

Console