当前位置:网站首页>用对象字面量或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;
},边栏推荐
猜你喜欢
随机推荐
JMeter tutorial (a)
scratch学习相关资料汇总
【AutoSAR 六 描述文件】
【组成原理 五 系统总线】
正则表达式
Omni-channel e-commerce | How can well-known domestic cosmeceuticals seize the opportunity to achieve rapid growth?
LeetCode 1047 Remove all adjacent duplicates in a string
[mathematical foundation] higher mathematics concept learning
RNA修饰技术介绍|介孔二氧化硅纳米颗粒(MSN)搭载的微小RNA-24(miR-24)纳米载体复合物
m10
荧光量子点修饰siRNA-QDs|纳米金修饰siRNA-Au(RNA修饰方式方法)
Xcode如何利用预览(Preview)让SwiftUI视图快速适配不同尺寸的设备
Briefly talk about K-means clustering
ESP8266-Arduino编程实例-I2C设备地址扫描
internship:利用easypoi将excel表数据导入导出
ESP8266-Arduino编程实例-LittleFS及数据上传
经验分享|编写简单易用的在线产品手册小妙招
R语言对airbnb数据nlp文本挖掘、地理、词云可视化、回归GAM模型、交叉验证分析
scratch 编程 + 小学数学
sad rock

![[mathematical foundation] higher mathematics concept learning](/img/59/3e1608de63c60201b3e7aaaf032d42.png)







