【发布时间】:2021-12-16 13:17:42
【问题描述】:
我有一个 nuxt SSR 应用程序,我正在使用 axios 发出 HTTP 请求。当我使用 axios 从我的服务器收到错误时,我想将带有 vue 路由器的错误消息作为道具传递给我的错误页面,我已将其设置为 nuxt 详细信息here。
我目前在我的错误布局页面中使用composition API。如何使用 Vue 路由器将错误消息作为道具传递到 /layouts/error.vue 中的错误页面?我试过这样传递道具:
router.push({ path: '/error', name: 'error', params: {error: error.response.data}})
但是错误页面上的props 对象不包含错误数据。如上所述,我的错误页面使用的是组合 API:
import { defineComponent } from '@nuxtjs/composition-api';
export default defineComponent({
setup(props) {
return {
}
}
})
我试过了:
router.push({ name: 'error', props: { error: error.response.data} });
我已经试过了:
router.push({ path: '/error', props: { error: error.response.data} });
不过,props 在错误组件中没有错误数据 (/layouts/error.ts)
我目前使用的是 nuxt 2.15.7
【问题讨论】:
-
你能用回复样本更新你的问题吗?
标签: nuxt.js vue-router vue-composition-api