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.data2.数组转字符串
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)})