<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>演示methods</title>
</head>
<body>
<div id="app">
<h2>图书</h2>
<div>
你购买了{{book.name}}共{{book.count}}本---¥{{book.price}}/本
</div>
<div>
<!-- 注意括号,调用方法时要后缀括号 -->
总价:{{totalPrice()}}(折扣:{{discount}},邮费:{{deliver}})
</div>
</div>
<script src="../js/vue.js"></script>
<script>
let vm = new Vue({
el:'#app',
data:{
book:{id:1,price:10,name:'vue入门',count:1},
discount:0.8,
deliver:12
},
methods:{
//计算属性的结果,是可以缓存的。methods函数是每次都执行的。效率不同。
totalPrice:function () {
return (this.book.price * this.book.count) * this.discount + this.deliver;
}
}
})
</script>
</body>
</html>
vue-例2-9计算属性与methods的区别.html
原创
©著作权归作者所有:来自51CTO博客作者虾米大王的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
vue-例2-6计算属性.html
【代码】vue-例2-6计算属性.html。
javascript vue.js 前端 html 双向绑定 -
vue-例2-6计算属性2.html
【代码】vue-例2-6计算属性2.html。
javascript vue.js 前端 html 双向绑定 -
vue-例2-7演示计算属性.html
【代码】vue-例2-7演示计算属性.html。
javascript vue.js 前端 html Vue -
vue-例2-5属性绑定.html
【代码】vue-例2-5属性绑定.html。
javascript vue.js 前端 html Vue -
vue-其他计算属性2.html
【代码】vue-其他计算属性2.html。
javascript vue.js 前端 html Vue -
vue-例2-8演示计算属性setter.html
【代码】vue-例2-8演示计算属性setter.html。
javascript vue.js 前端 html Vue -
vue-例2-5属性绑定2.html
【代码】vue-例2-5属性绑定2.html。
vue.js javascript 前端 html Vue -
vue-其他计算属性.html
【代码】vue-其他计算属性.html。
vue.js javascript 前端 html Vue -
vue-例9-2演示路由传递参数.html
【代码】vue-例9-2演示路由传递参数.html。
javascript vue.js 前端 html Vue -
vue-例9-1演示Vue路由.html
【代码】vue-例9-1演示Vue路由.html。
javascript vue.js 前端 html Vue -
vue-例2-5属性绑定4.html
【代码】vue-例2-5属性绑定4.html。
javascript vue.js 前端 html 百度 -
vue-例2-5属性绑定3.html
【代码】vue-例2-5属性绑定3.html。
javascript vue.js 前端 html Vue -
vue-例2-2学习v-html.html
【代码】vue-例2-2学习v-html.html。
javascript vue.js 前端 html HTML -
vue-例9-5演示命名视图.html
【代码】vue-例9-5演示命名视图.html。
javascript 前端 vue.js html ide -
vue-例2-1模板语法.html
模板语法
vue.js javascript 前端 html HTML