保 洁 阿 姨

拥有60+年的前端设计经验

60+Years of front-end design experience

luzhou·sichuan

www.usuuu.com

Web网页设计:70888820

4个视频

Video list

Nuxt3请求错误拦截(自定义错误页面)

IP属地:四川省 / 发布于:4个月前 / 浏览:664

接收Error

例如:

/**
 * 菜单详情
 */
const { data, error } = await menuShowApi(menuId)

判断error是否有值

/**
 * 服务端时并且error有值就抛出错误
 */
if(process.server && error.value){
    showError('请确认链接是否正确')
}

自定义错误

根目录新建一个error.vue

<template>
    <clientOnly>
        <div class="app-error">
            <p>{{ error.message }}</p>
            <a @click="handleError">返回首页</a>
        </div>
    </clientOnly>
</template>
<script lang="ts" setup>
/**
 * 接收错误信息
 */
const props = defineProps({ 
    error: { 
        type: Object,
        required: true 
    }
})
/**
 * 清除错误信息并返回首页
 */
const handleError = () => {
    clearError({ redirect: '/' })
}
</script>

说明

{{ error.message }}等于showError('请确认链接是否正确')

Nuxt3请求接口封装(精简)-TypeScript

给Ta打赏
共0人打赏

打赏的土豪们

Rewarded users

暂无打赏

© 未经允许禁止转载
回复
暂无数据

暂无数据

Vexip UI

Ui components

VexipUI提供了一系列开箱即用的组件,并使用全新的Vue3.0组合式Api编写,一款值得关注的Vue3UI组件库

Vexip UI

用户签到

User Sign

签到奖励积分

站点公告

Announcement

(友情链接)2023-3-21清除单项链接
Web网页设计交流群:70888820
QQ号为523179414的狗,谢绝访问

版权申明

本站原创内容版权遵循 CC-BY-NC-SA 协议规定,转载请注明出处.本站部分资源收集于网络,只做学习和交流使用,版权归原作者所有.