当前位置:网站首页>计算属性的作用及使用?
计算属性的作用及使用?
2022-08-04 05:26:00 【狐逍超】
计算属性
主要作用:进行复杂业务逻辑的处理(具有缓存功能)。
语法:computed:{计算属性: function(){return}} --固定写法
主要特性:只要计算属性中的依赖项发生变化时,这个属性的值就会自动变化,所以与之相关联的DOM也会变化。
代码演示:
computed: {
//调用方法:{
{getTotalPrice}}--不加()--名字自定义
getTotalPrice() {
//业务的处理
let total = 0;
this.list.forEach((value) => {
total += value.price;
});
//返回业务处理后的结果
return total;
},
注意:对于复杂的逻辑处理,都可以考虑使用计算属性来处理。
边栏推荐
猜你喜欢

npm报错Beginning October 4, 2021, all connections to the npm registry - including for package installa

DP4398:国产兼容替代CS4398立体声24位/192kHz音频解码芯片

解决JDBC在web工程中无法获取配置文件

webrtc中的任务队列TaskQueue

Web Basics and Exercises for C1 Certification - My Study Notes

Can‘t connect to MySQL server on ‘localhost3306‘ (10061) 简洁明了的解决方法

OpenSSF 安全计划:SBOM 将驱动软件供应链安全

Summary of MySQL database interview questions (2022 latest version)

【Matlab仿真】:一带电量为q的电荷以速度v运动,求运动电荷产生磁感应强度

scrapy 爬取当当图书名字图片
随机推荐
LCP 17. Quick Calculation Robot
webtrc 中VideoAdapter类中的作用及局限
npm报错Beginning October 4, 2021, all connections to the npm registry - including for package installa
CentOS7 —— yum安装mysql
MediaCodec支持的类型
去重的几种方式
想好了吗?
The cost of automated testing is high and the effect is poor, so what is the significance of automated testing?
8款最佳实践,保护你的 IaC 安全!
渗透测试(PenTest)基础指南
利用Jenkins实现Unity自动化构建
JS basics - forced type conversion (error-prone, self-use)
7.16 Day22---MYSQL(Dao模式封装JDBC)
[原创]STL容器map和unordered_map性能,创建,插入,随机访问速度对比!
warning C4251: “std::vector<_Ty>”需要有 dll 接口由 class“Test”的客户端使用错误
跳转页面实时调用后台接口,更新页面数据
Several ways to heavy
Programming hodgepodge (4)
关于事件捕获和事件冒泡的顺序,以及如何处理事件冒泡带来的影响
再识关联容器