希望对你有帮助
html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.0.3/vue.js"></script>
<div id="app">
{{ book.name }} - ¥{{ book.price }} - {{ book.count }}
<hr />
总金额: {{ all1 }}
<hr />
<button @click="addPrice">价格+1</button>
<button @click="addCount">总数+1</button>
</div>
</body>
</html>
js
new Vue({
el: '#app',
data: {
book: {
id: 1,
name: 'vue入门',
price: 10,
count: 5
},
discount: 0.8,
deliver: 10
},
methods: {
addCount: function() {
this.book.count += 1;
},
addPrice: function() {
this.book.price += 1;
}
},
computed: {
all1: function() {
return this.book.price * this.book.count
}
}
})
预览:
本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网