首页 > 其他 > 详细

记项目中易出现的bug点

时间:2019-03-18 12:37:45      阅读:115      评论:0      收藏:0      [点我收藏+]

1. 弹框组件,初始化数据的方法写在created 中

 bug 点:created 钩子函数只在页面第一次加载时执行,第二次加载则不会执行,初始化数据无法更新。

 示例:页面不刷新的情况下,弹框组件第二次打开时,detail 是不会变化的

 created () {
    this.getDetail()
  },
  methods: {
    getDetail () {
      this.$http(‘post‘, `/api/${this.id}`)
        .then((res) => {
          if (res.statusCode === 200) {
            let result = res.data
            this.alarmDescription = Object.assign(this.alarmDescription, result.alarmDescription)
            this.alarmContentType = result.alarmContentType
          }
        })
        .catch((e) => {
          console.log(e)
        })
    }, 

解决办法: watch 一下id 的变化,同时要在关闭弹框的回调事件中改变一下id, 这样避免连续打开同一条记录(id不变)时,也刷新数据。

  watch: {
    id: function (val) {
      if (this.id) {
        this.getDetail()
      }
    }
  },  

2. form 表单,要有清空操作

3. try catch 无法抓取异步方法中的错误

4. 双向绑定复杂对象,当参数传递前要 JSON.parse(JSON.stringify(this.searchForm)),避免参数对象中的数据随页面发生变化。

 

 

记项目中易出现的bug点

原文:https://www.cnblogs.com/caolidan/p/10550705.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!