工作常见问题解决


本次博客,主要用于开发过程中发现问题的解决方法,会涉及到使用步骤及功能,不涉及原理、参数。如果想知道具体使用原理,请参考其他内容

组件问题

keep-alive缓存

在组件切换过程中 把切换出去的组件保留在内存中,防止重复渲染DOM,减少加载时间及性能消耗,提高用户体验性,
方法步骤:
1、在你需要缓存的位置添加keep-alive(注意一定有两个判断)

<el-main>
          <keep-alive>
            <v-content v-if="$route.meta.keepAlive">
            </v-content>
          </keep-alive>
          <v-content v-if="!$route.meta.keepAlive">
          </v-content>
 </el-main>

2、在router.js中添加keepAlive:true

{
   path: '/inhabitant/inhabitantlist',
   name: 'inhabitantlist', //居民列表
   meta: {
   	 title: '居民列表',
   	 requireAuth: true, // 添加该字段,表示进入这个路由是需要登录的
     keepAlive:true
   },
   component: () =>
   	import('../components/inhabitall/inhabitant/inhabitantlist.vue'),
   },

3、还有另外一种方法也可以达到效果(第一步和这一步的相加),在你需要缓存的下一个路由中添加以下字段,该字段与create同级

beforeRouteLeave(to, from, next) {
     to.meta.keepAlive = true;
     next()
   },

$router-replace和push的区别

两者相同点,都可以到达制定路由,
不同之处,replace相当于单向发送,使用router.replace()方法,不会向history栈添加一个新纪录,成功跳转后点击浏览器的回退按钮会到上上个页面 、常用于登录等页面

push这个方法会向history栈添加一个新纪录,成功跳转后点击浏览器的回退按钮会跳回之前的页面

bug问题查询解决

服务器端500错误

目前有两种解决方式
1、是后端问题,跨域
2、前端发送给后端的数据有错误、排查后没有问题还是报错,可以再测试下别的接口是否有同样的问题,如果问题同样,则可以找后端修改

the server responded with a status of 404 (Not Found)

翻译:加载资源失败:服务器响应404 (Not Found):8020/favicon.ico:1,请求某一资源失败
解决方法:刷新

常见正则表达式

手机号判断

/^1(3|4|5|6|7|8)\d{9}$/

猜你喜欢

转载自blog.csdn.net/m0_69327201/article/details/128805963