在将this.queryForm.Arraypronew置空时,前端VUE报this.queryForm.Arraypronew.join is not a function,怎么解决这个报错并把this.queryForm.Arraypronew.join(',')置为空
时间: 2024-04-11 07:29:09 浏览: 20
报错`this.queryForm.Arraypronew.join is not a function`说明`this.queryForm.Arraypronew`不是一个数组,而是一个非数组的值。因此,不能直接调用数组的`join`方法。
要解决这个问题,你需要在将`this.queryForm.Arraypronew`置为空之前,先确保它是一个空数组。可以使用以下代码进行修改:
```javascript
this.queryForm.Arraypronew = [];
```
这将将`this.queryForm.Arraypronew`重置为空数组。然后,你就可以安全地调用`join`方法来将其转换为字符串,并将其置为空字符串:
```javascript
this.queryForm.Arraypronew.join(',') = '';
```
这样就可以避免报错,并将`this.queryForm.Arraypronew.join(',')`置为空字符串。
相关问题
在代码中打印出this.queryForm.crteTimeOption的值 为 空,啥也没有打印出来
如果在代码中打印出this.queryForm.crteTimeOption的值,发现它为空,那么可能是因为在代码中对this.queryForm.crteTimeOption赋值的操作还没有执行。
你可以检查一下代码,看看是否有对this.queryForm.crteTimeOption赋值的操作,并且该操作是否在打印操作之前执行。如果确实存在这样的情况,那么你需要将打印操作放在对this.queryForm.crteTimeOption赋值的操作之后执行,这样就可以正确地打印出this.queryForm.crteTimeOption的值了。
解析这段代码:async getDataList() { this.dataLoading = true for(let i =0; i<this.queryForm.Arraykh.length; i++){ this.queryForm.Arraykhnew[i] = '\'' + this.queryForm.Arraykh[i] +'\'' } for(let i =0; i<this.queryForm.Arraypro.length; i++){ this.queryForm.Arraypronew[i] = '\'' + this.queryForm.Arraypro[i] +'\'' } let res = await this.$http.get('/sms/sms-qa-accident/page', { params: { id: this.queryForm.id, kh: this.queryForm.Arraykhnew.join(','), pro: this.queryForm.Arraypronew.join(','), Arraykh: this.queryForm.Arraykh.join(','), Arraykhnew: this.queryForm.Arraykhnew.join(','), current: this.pageIndex, size: this.pageSize } })
这段代码是一个异步函数`getDataList()`,它用于获取数据列表。
首先,代码中设置了一个变量`dataLoading`为true,用于表示数据加载中。
然后,通过for循环遍历`this.queryForm.Arraykh`数组,对每个元素进行处理并存储到`this.queryForm.Arraykhnew`数组中。具体处理方式是在元素两侧添加单引号。
接着,再次通过for循环遍历`this.queryForm.Arraypro`数组,对每个元素进行处理并存储到`this.queryForm.Arraypronew`数组中。同样,处理方式是在元素两侧添加单引号。
在之后的代码中,使用`this.$http.get`方法发送一个GET请求到指定的URL `/sms/sms-qa-accident/page`。请求参数包括:
- `id`: `this.queryForm.id`
- `kh`: `this.queryForm.Arraykhnew.join(',')`
- `pro`: `this.queryForm.Arraypronew.join(',')`
- `Arraykh`: `this.queryForm.Arraykh.join(',')`
- `Arraykhnew`: `this.queryForm.Arraykhnew.join(',')`
- `current`: `this.pageIndex`
- `size`: `this.pageSize`
最后,返回获取到的响应结果给变量`res`。