vue之字符串、数组之间的相互转换方式
作者:new-lijiabin
这篇文章主要介绍了vue之字符串、数组之间的相互转换方式,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
vue字符串、数组之间的相互转换
字符串如何转数组
str.split(';'); //以分号拆分字符串数组如何转字符串
arr.join(';'); //把数组项拼接成字符串,并以分号隔开。默认情况下是以逗号隔开vue element项目中数组转字符串 字符串转数组
数组转字符串
备注(主要是这句):
this.modifyForm.prefecture =this.modifyForm.prefecture.toString()
async handleAdclick() {
this.modifyForm.prefecture = this.modifyForm.prefecture
.toString()
.replace(/,/gi, '|')
const result = await addCustomer(this.modifyForm)
if (result.code === 200) {
/* 添加完置空表单 */
this.modifyForm = {
address: '',
age: '',
avatar: '',
mobile: '',
memo: '',
conditionTags: '',
email: '',
employeeId: '',
enterpriseWechatTags: '',
name: '',
rfmtags: '',
sex: true,
sources: '',
wxNickname: '',
prefecture: ''
}
this.$message.success('添加成功')
this.$router.go(-1)
} else {
this.$message.error('添加失败')
}
}字符串转数组
备注(主要是这句):
this.distrubuteForm.ids = this.writerAnotherId.split(‘,')
(我这里有个字段赋值,对应好你的字段即可)
async handleAdclick() {
this.distrubuteForm.ids = this.writerAnotherId.split(',')
const result = await distrubuteCustom(this.distrubuteForm)
if (result.code === 200) {
/* 添加完置空表单 */
this.distrubuteForm = {
crmId: '',
followUpUserId: '',
ids: [],
optUserId: ''
}
this.$message.success('分配成功')
this.distributionDialogVisible = false
this.getList()
} else {
this.$message.error('分配失败')
}
}总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
