vue el-input数据处理问题?-灵析社区

winkkkkk9421

要求el-input输入的值是数字数组形式:[123,123],组件定义的value是string类型,所以在查询的时候需要对input输入的值进行转换。 我的处理方式: // 处理表单所有元素数据 // 处理表单所有元素数据 handleAllFormItem () { // 处理空数据 let newForm = {} let objs = {} let obj = {} const { searchForm } = this // 处理工单号 let str = searchForm.ticket_id if(typeof str !== 'undefined') { const tickId = str.split(',').map(Number) objs = { ticket_id: tickId } } obj = {...searchForm, ...objs} console.log(obj, 'searchForm------') newForm = this.handleFormFormat(obj) // newForm = { ...this.handleFormFormat(searchForm), ...objs} return newForm }, handleFormFormat方法是处理动态表单数据格式化的: handleFormFormat (searchForm) { const newForm = {} for (const key in searchForm) { let item = this.searchForm[key] // bool 非整数字符串 if ( typeof item === 'boolean' || typeof item === 'number' || (!Array.isArray(item) && isNaN(Number(item))) ) { newForm[key] = item continue } // 整数字符串,数组 if (item && item.length > 0) { if (Array.isArray(item)) { let arr = [] item.forEach((it) => { if (!isNaN(Number(it))) { it = Number(it) } arr.push(it) }) newForm[key] = arr continue } if (!isNaN(Number(item))) { item = Number(item) } newForm[key] = item } } return newForm }, 什么条件不输的时候查出的结果打印: ![image.png](https://wmprod.oss-cn-shanghai.aliyuncs.com/images/20250103/ef1dc5fa5e909a4ee06232e95bb6a8ee.png) 输入数字后查询打印结构(显示数据处理过后的): ![image.png](https://wmprod.oss-cn-shanghai.aliyuncs.com/images/20250103/a788ce33654bd3b1800adcc111ec41cf.png) 但是network传的值却没有改变,还是字符串形式的: ![image.png](https://wmprod.oss-cn-shanghai.aliyuncs.com/images/20250103/c655a3c6e22965674c8841990246c7a9.png) 求助大佬提点一下,哪里问题

阅读量:13

点赞量:0

问AI
无语,ticket_id你是不是定义的是一个数组??其实你可以定义字符串,提交的时候再判断它有没有值,有值的话转数组。。。你这个是数据类型的问题。。。就好比el-date组件里面使用2个日期,你定义字符串,会报错的,它要求是数组。。。。大概是这个意思,你的明白?你不明白也没有关系,我自己整的也不会了