使用 Vuetify 设置一个 nuxt 项目。其中一页使用client-only( no-ssr) 组件。在开发过程中,如果此组件出现错误,我会被重定向到默认错误页面,这会阻止我使用 Vue devtools 检查变量和组件。
我觉得它应该很简单,但我找不到禁用这种自动重定向行为的方法。所以我想我的问题是如何禁用 nuxt 默认错误重定向?
我发现了一个带有 nuxt 插件的黑客:
./plugins/errors.js
export default function({ app }) {
app.nuxt.error = () => {}
}
Run Code Online (Sandbox Code Playgroud)
./nuxt.config.js
module.exports = {
...
plugins: [
"~/plugins/errors.js",
],
}
Run Code Online (Sandbox Code Playgroud)
<nuxt-error>您无法从 nuxt 配置中禁用渲染。
另一种方法是破解 nuxt 渲染,如下所示:
1/ 打开文件./node_modules/@nuxt/vue-app/template/components/nuxt.js
2/ 转到render(h)方法
3/ 删除错误条件以始终显示组件:
render (h) {
// HACK TO SKIP ERROR
this.nuxt.err = false
// if there is no error
if (!this.nuxt.err) {
// Directly return nuxt child
return h('NuxtChild', {
key: this.routerViewKey,
props: this.$props
})
}
// ...
}
Run Code Online (Sandbox Code Playgroud)
注意:每次npm或yarn安装后,上面文件中的 hack 都会被覆盖。
| 归档时间: |
|
| 查看次数: |
1652 次 |
| 最近记录: |