问题:
今天工作中碰到一个问题,当我点击关闭时间下行的事件有效时间及时间选择器是不出现的.当我点击开启的时候出现.这时发现新增对话框里面没有问题,但是当我在编辑的情况下,我点击开启时,事件有效时间这个文本出现了,但是时间选择器却没有出现.之后发现报了下图的错.
我看不懂浴室去查了相关资料.这里可以注意到是提示我们null
解决办法:
首先呢,这是数组没值导致的问题,所以就需要
数组赋值字段为null
Error in getter for watcher “parsedValue”: “TypeError: Cannot read property ‘length’ of null”
接口返回字段给数组设置默认值时,注意返回字段为null, 而不是空字符串,会报以上错误
所以我们需要时间这个数组赋值为空字符串
这是之前的代码
//编辑事件
showsenior(index, row) {
console.log(888, row);
this.modeltype = "edit";
this.showAddShijian = true;
this.Goodspro = row;
console.log(99999, this.Goodspro);
this.Goodspro.prop_id = row.change_id;
this.Goodspro.time = [row.begin_time, row.end_time];
this.Goodspro.aop_id = row.aop_id;
this.Goodspro.item_code = this.item_code;
},
这是之后的代码
//编辑事件
showsenior(index, row) {
console.log(888, row);
this.modeltype = "edit";
this.showAddShijian = true;
this.Goodspro = row;
console.log(99999, this.Goodspro);
this.Goodspro.prop_id = row.change_id;
if (row.limit_time == 1) {
this.Goodspro.time = [row.begin_time, row.end_time];
}
this.Goodspro.aop_id = row.aop_id;
this.Goodspro.item_code = this.item_code;
},
其实还需要在编辑的时候,去判断一下如果是开启状态才给我们的time赋值,否则就不赋值.因为如果没有判断的话,我们可以看到关闭的时候,time被赋值以后就是null了.
思路来自于下面的作者博文:
https://www.jianshu.com/p/24b79ab693ee