设计模式-策略模式

Voun MAX++

vue中应用策略模式

减少if elseif 判断

使代码更加简洁,易于拓展

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<template>
<el-row v-for="(item,index) in list" :key="index">
<el-col :span="16">{{item.title}}</el-col>
<el-col :span="8">
<el-tag :type="type[item.type].tagType">{{type[item.type].status}}</el-tag>
</el-col>
</el-row>
</template>
<script setup>
const list=ref([
{
title:'文章1',
type:1
},
{
title:'文章2',
type:2
},
{
title:'文章3',
type:3
},
])
let type=ref([
{
status:'待审核',
tagtype:'warning'
},
{
status:'已通过',
tagtype:'success'
},
{
status:'未通过',
tagtype:'danger'
}
])
</script>
  • 标题: 设计模式-策略模式
  • 作者: Voun
  • 创建于 : 2024-06-17 16:24:55
  • 更新于 : 2024-08-13 05:34:44
  • 链接: http://www.voun.top/2024/06/17/23-设计模式-策略模式/
  • 版权声明: 本文章采用 CC BY-NC-SA 4.0 进行许可。
评论
此页目录
设计模式-策略模式