Vue——使用 computed 计算属性
根据人次数值分别展示不同得背景色
<span style="font-weight:600">用户位置</span>
<divclass="mt-4"id="login-location":style="{ float: 'left', width: '100%' }"
><v-data-table:headers="location_headers":items="locations"class="elevation-0":hide-default-footer="true":disable-sort="true":fixed-header="true"no-data-text="暂无数据"><templatev-slot:[`item.value`]="{ item }"v-if="locations.length > 0"><v-chip :color="getColor(locationsNum, locations, item.value)">{{ item.value }}</v-chip></template></v-data-table>
</div>export default {data() {return {locations: [{"name": "广西","value": 3},{"name": "南宁","value": 1}],location_headers: [{text: "位置名称",value: "name"},{text: "人次",value: "value"}],};},methods:{getColor(statistic_num, curdata, num) {let curdataLen = curdata.length;let avg = num / (statistic_num / curdataLen) / 2;return `rgba(0,118,196,${avg})`;}},computed: {locationsNum() {let s = 0;for (let item of this.locations) {s += item.value;}return s;}}
};
Vue——使用 computed 计算属性相关推荐
- Vue中computed计算属性和data数据获取的问题
获取到数据(对象.数组),截取一部分显示到页面中,用computed计算属性来实现截取数据然后直接输出到页面. <div class="detailBox"><h ...
- Vue中computed(计算属性)、methods、watch的区别
初学vue,阅读api后,发现Vue提供了多种逻辑处理的方法,单纯的方法methods,computed(计算属性)以及watch等,充分理解这三者的区别,才能写出更加健壮的Vue代码. 1.meth ...
- vue的computed计算属性学习
模板内的表达式是非常便利的,但是它们实际上只用于简单的运算.在模板中放入太多的逻辑会让模板过重且难以维护.这时候需要使用到vue的计算属性computed. 文件目录结构如下:利用vue脚手架创建 这 ...
- vue 中 computed 计算属性 的用法
计算属性实质就是一个方法,只不过在使用的时候只把方法名称作为属性使用,不需要加(),而不是当做方法使用. 只有计算属性的方法内部所用到的任何data中的数据发生变化,就会立刻重新计算这个计算属性的值. ...
- Vue的computed(计算属性)使用实例之TodoList
最近倒腾了一会vue,有点迷惑其中methods与computed这两个属性的区别,所以试着写了TodoList这个demo,(好土掩面逃~); 1. methods methods类似react中组 ...
- 面试题!vue中的计算属性、方法、侦听属性
1.计算属性 详细的内容可跳转至vue 计算属性 可以使用计算属性来代替在表达式中进行的复杂运算,以便于能够更方便的维护与复用逻辑. 计算属性是在选项对象中使用 computed 字段来定义. 特点: ...
- 深入理解 Vue Computed 计算属性
Computed 计算属性是 Vue 中常用的一个功能,我们今天来说一下他的执行过长 拿官网简单的例子来看一下: <div id="example"><p> ...
- Vue中的computed计算属性
文章目录 computed与watch的异同 不同点 相同点 示例 源码 结果 分析 computed与watch的异同 不同点 触发条件不同 computed计算属性会依赖于使用它的data属性 ...
- Vue入门【三】-- 详解computed计算属性
目录 computed: ♡ ‧₊˚ 基本使用 ‧₊˚ ♡ ♡ ‧₊˚语法‧₊˚ ♡ ♡ ‧₊˚效果‧₊˚ ♡ ♡ ‧₊˚ 面试问点 ‧₊˚ ♡ computed与methods的区别: comput ...
最新文章
- xftp permission is not allowed
- Data Lake Analytics的Geospatial分析函数
- 【 Laravel 】日 常 整 理 记 录 分 享
- centos7下qt creator python配置
- expected dense_10_input to have shape (13,) but got array with shape (1,)
- Altium Designer敷铜的规则设定
- iOS多线程:『pthread、NSThread』详尽总结
- 乔春洋:品牌管理创新
- Android系统优化(65)---MTK 平台开关机、重启时间优化
- sscanf_s函数用法
- 《达拉崩吧》扣哒世界版——在扣哒世界中学习编程
- 数据传输服务器系统图,档案数字化管理系统
- 伴随矩阵例题_§6伴随矩阵及练习题.ppt
- 操作系统中文件存储空间的管理
- 电力电子与电力传动类毕业论文文献包含哪些?
- 怎么设置可以将资料横向打印出来
- 手机token登入软件_app开发调试工具_app开发token使用
- TiDB:基于 Raft 的 HTAP 数据库
- 服务器显卡芯片,Intel服务器独立显卡单卡四芯原来如此
- Matlab程序设计语言基础