vue 参数拼接没有值问题?
vue 参数拼接没有值问题?
如下提交方法:
handleHighSubmit(data) { this.serverData = { ...data }
const new_str = [this.form.server_str, this.serverData.highServer].join(',')
let params = {
choice: this.choice,
filter_condition: {
server_str: new_str,
...this.form
}
}
console.log(params, 'params---');
this.getCoverUsers(params)
this.handleClose()
},
我在控制台打印的this.form.server_str值为字符串'123'
和this.serverData.highServer的值为‘[2-3]’
,它们都有值,,然后通过join拼接到一块当做参数传递,拼接后的值是'123,[2-3]',但是提交到接口为什么就只有this.form.server_str值,没有this.serverData.highServer的值
回答:
用 Vue.nextTick :
handleHighSubmit(data) { this.serverData = { ...data };
this.$nextTick(() => {
const new_str = [this.form.server_str, this.serverData.highServer].join(',');
let params = {
choice: this.choice,
filter_condition: {
server_str: new_str,
...this.form
}
};
console.log(params, 'params---');
this.getCoverUsers(params);
this.handleClose();
});
},
回答:
filter_condition: { server_str: new_str,
...this.form
}
this.form里是不是有server_str字段,params里的被覆盖了吧
回答:
应该是值被覆盖了,调换下代码顺序如下:
filter_condition: { ...this.form,
server_str: new_str
}
以上是 vue 参数拼接没有值问题? 的全部内容, 来源链接: utcz.com/p/935177.html