简体   繁体   English

如何在 nuxt 中制作 *.vue 文件

[英]How to make *.vue file in nuxt

I know that my question seems weird but I'm seriously lost in here, I read some article to redirect all not-found page in nuxt to / or home or index but in this tutorial tell me to make page/*.vue .我知道我的问题看起来很奇怪,但我在这里迷失了方向,我读了一些文章将 nuxt 中所有未找到的页面重定向到/homeindex但在本教程中告诉我制作page/*.vue First of all I know that * this asterisk symbol means all but whenever I try to make *.vue file it always give me not valid files in Visual Studio Code .首先,我知道*这个asterisk符号意味着all ,但每当我尝试制作*.vue文件时,它总是给我在Visual Studio Code中无效的文件。 can someone help me to solve this?有人可以帮我解决这个问题吗?

this is the article that I read redirect-404-not-found-in-nuxt-js I already try the code in this article and it works and redirect my 404.vue page to home but it is not the solution I seek since it means I must declare all possible file for not found and of course it is not a good solution.这是我阅读的文章redirect-404-not-found-in-nuxt-js我已经尝试了本文中的代码,它可以工作并将我的404.vue页面重定向到主页,但这不是我寻求的解决方案,因为它意味着我必须声明所有可能的文件未找到,当然这不是一个好的解决方案。

this is the 404.vue code that I want to use in *.vue :这是我想在*.vue中使用的404.vue代码:

<!-- pages/*.vue -->
<script>
export default {
  asyncData ({ redirect }) {
    return redirect('/')
  }
}
</script>

*.vue is not a valid file name. *.vue 不是有效的文件名。 I didn't use Nuxt when creating my 404 page - I just used regular old Vue.创建 404 页面时我没有使用 Nuxt - 我只是使用了普通的旧 Vue。

First I created a component and called mine notFoundComponent.vue (can call yours whatever) and created a View as well and called that notFoundView.vue.首先,我创建了一个组件并命名为我的 notFoundComponent.vue(可以调用你的),并创建了一个视图并将其命名为 notFoundView.vue。 I then coded those pages to display the 404 error how I wanted.然后我对这些页面进行编码以显示我想要的 404 错误。

On my router.js page, I added the following to the end of the routes and it works as intended:在我的 router.js 页面上,我在路由的末尾添加了以下内容,它按预期工作:

{ name: 'notFoundView', path: '*', component: notFoundView }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM