首页 > 编程知识 正文

js字符串数组转字符串,js数组转数字

时间:2023-05-04 02:51:53 阅读:263208 作者:2993

1.字符串转数组

const res = await api.getManyParams(this.cateId, 'many')if (res.meta.status !== 200) { return this.$message.error('获取动态参数列表失败')}res.data.forEach( item => {//将后端每一项的字符串用空格分开变成数组 item.attr_vals = item.attr_vals.length === 0 ? [] : item.attr_vals.split(' ')})this.manyTableData = res.data

2.数组转字符串

this.$refs.addFormRef.validate((valid) => { if (!valid) { return this.$message.error('请填写必要的表单项') } //执行添加的业务逻辑 //将数组变成用,连接的字符串,需要深拷贝 //方法一——lodash 前提: npm i lodash -S 以及页面中引入 import _ from 'lodash' // const form = _.cloneDeep(this.addForm) // form.goods_cat = form.goods_cat.join(',') // console.log(form) //方法二——JSON.parse,stringify const form = JSON.parse(JSON.stringify(this.addForm)) form.goods_cat = form.goods_cat.join(',') console.log(form)})

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。