问题:如果一个404页面有不同的展示,比如详情页的404和个人页的404也许只是文字和图标的不同,我们可以利用new Map根据后端传来的code做出对应的展示。
const errorCfg = new Map([
[-9106, {
icon: 'xxx1',
text: '已删除',
}],
[-9107, {
icon: 'xx2',
text: 'id不存在',
}],
[-9108, {
icon: 'xx3',
text: '审核中',
}],
[-9109, {
icon: 'xx4',
text: '审核拒绝',
}],
])
const { errorCode } = toRefs(props). //props 后端的code
const currentError = computed(() => errorCfg.get(errorCode.value))
<template>
<div
>
<img
:src="currentError.icon"
/>
<div>
{
{ currentError.text }}
</div>
</div>
</template>
或者直接利用对象
const errorCfg = {
-106: {
icon: 'xxx1',
text: '已删除',
},
-107: {
icon: 'xx2',
text: 'id不存在',
},
-108: {
icon: 'xx3',
text: '审核中',
},
-109: {
icon: 'xx4',