nuxt中配置404页面方法详解
                
        
                
        Vue
                
        2020-06-17 17:24:13
            
nuxt.js的应用随着SEO要求的增加而逐渐广泛,那么在nuxt.js中我们要如何设置404页面呢?
开始之前,我们可以先通过下图得出下方数据,根据数据来进行对应的处理!

从上图中,我么可以得出状态码、路径、提示信息。
是不是可以这么理解,通过这些状态码,我们可以在页面中进行判断性的页面内容展示。
错误页面配置步骤:
1、在layouts文件夹下加error.vue文件
<template>
  <div class="__nuxt-error-page">
    <div class="error">
      <svg xmlns="http://www.w3.org/2000/svg" width="90" height="90" fill="#DBE1EC" viewBox="0 0 48 48">
        <path d="M22 30h4v4h-4zm0-16h4v12h-4zm1.99-10C12.94 4 4 12.95 4 24s8.94 20 19.99 20S44 35.05 44 24 35.04 4 23.99 4zM24 40c-8.84 0-16-7.16-16-16S15.16 8 24 8s16 7.16 16 16-7.16 16-16 16z" />
      </svg>
      <div class="title">{{ error }}</div>
    </div>
  </div>
</template>
<script>
export default {
  name: 'test',
  computed: {
  },
  props: ['error'],
  head () {
    return {
      title: this.message,
      meta: [
        {
          name: 'viewport',
          content: 'width=device-width,initial-scale=1.0,minimum-scale=1.0'
        }
      ]
    }
  }
}
</script>
<style>
.__nuxt-error-page {
  padding: 1rem;
  background: #F7F8FB;
  color: #47494E;
  text-align: center;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  font-family: sans-serif;
  font-weight: 100 !important;
  -ms-text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}
.__nuxt-error-page .error {
  max-width: 450px;
}
.__nuxt-error-page .title {
  font-size: 1.5rem;
  margin-top: 15px;
  color: #47494E;
  margin-bottom: 8px;
}
.__nuxt-error-page .description {
  color: #7F828B;
  line-height: 21px;
  margin-bottom: 10px;
}
.__nuxt-error-page a {
  color: #7F828B !important;
  text-decoration: none;
}
.__nuxt-error-page .logo {
  position: fixed;
  left: 12px;
  bottom: 12px;
}
</style>2、打印的error信息,我们可以根据打印信息数据判断当前是404页面抑或是503等提示。
		    
		        六月初字帖坊小程序 
		    
		     你想要的字帖模板及工具,这里都有! 
		
				899篇文章
				4774人已阅读
			
			
			
		
				        
六月初