当前位置:网站首页>用对象字面量或Map替代Switch/if语句
用对象字面量或Map替代Switch/if语句
2022-07-29 19:49:00 【无围之解】
用对象字面量或Map替代Switch/if语句
<template>
<div class="wrapper">
<h3>
用对象字面量或Map替代Switch/if语句
</h3>
</div>
</template>
<script>
export default {
name: "Table",
data() {
return {};
},
methods: {
toChange1(color) {
// use switch case to find yours
switch (color) {
case "red":
return ["apple", "strawberry"];
case "yellow":
return ["banana", "pineapple"];
case "purple":
return ["grape", "plum"];
default:
return [];
}
},
toChange2(color) {
const fruitColor = {
red: ["apple", "strawberry"],
yellow: ["banana", "pineapple"],
purple: ["grape", "plum"],
};
const data = fruitColor[color] || [];
return data;
},边栏推荐
- LeetCode_474_ one and zero
- 【AutoSAR 五 方法论】
- MATLAB程序设计与应用 2. 第2章 MATLAB数据及其运算 2.1 MATLAB数值数据 && 2.2 MATLAB矩阵的表示 && 2.3 变量及其操作
- JSP Servlet JDBC MySQL CRUD 示例教程
- mysql get field comments and get table fields
- 第二增长曲线 | 企业创新突破停滞困境的驱动指南
- JMeter使用教程(一)
- EasyExce template filling generation of Excel of actual operation, many processing sheet page
- 荣耀的野望:智慧世界的“高端平民”
- 这半年我做交易链路自动化回归的那些事儿...
猜你喜欢

解决宝塔mysql 远程root 无法连接问题

尿素偶联Urea-siRNA Conjugates|Cyclodextrin-siRNA-β-CD环糊精修饰RNA核酸(解析说明)

单壁碳纳米管-DNA复合物(SWCNT-DNA)|作用机理

In the past six months, I have done those things about the automatic return of the transaction link...

12437字,带你深入探究RPC通讯原理

The ambition of glory: "high-end civilians" in a smart world

C language learning books (improvement)

The second growth curve | The driving guide for corporate innovation to break through the stagnation dilemma

这半年我做交易链路自动化回归的那些事儿...

【Autosar 启动流程详解】
随机推荐
全排列的一点小技巧:康托展开
正则表达式
荣耀的野望:智慧世界的“高端平民”
[GXYCTF2019] ban dolls
线程的六种状态
ESP8266-Arduino programming example-I2C device address scan
程序员如何提升自己写代码的能力?
scratch学习相关资料汇总
这半年我做交易链路自动化回归的那些事儿...
RNA的化学修饰原理|Gal-PEG-siRNA|siRNA-S-S-DSPE|siRNA-s-s-PEG|cholesterol-siRNA
shell 图形化跳板机
Expert advice | How to formulate a growth strategy for survival in an economic downturn
接口测试工具之Postman详解
[数学基础]概率论与数理统计相关概念学习
Mass data query scheme mysql_Mysql massive data storage and solution 2 - Mysql sub-table query massive data... [easy to understand]
Monitoring basic resources through observation cloud monitor, automatic alarm
Kotlin - 协程作用域 CoroutineScope、协程构建器 CoroutineBuilder、协程作用域函数 CoroutineScope Functiom
ESP8266-Arduino programming example-EEPROM read and write
mysql 获取字段注释 和获取表字段
华为笔记本键盘锁住了(笔记本电脑键盘怎么亮起来)