powerdong / myProblems

我用到了,你可能用到
0 stars 1 forks source link

表单常用技巧 #36

Open powerdong opened 4 years ago

powerdong commented 4 years ago
// 过滤不要的数据
const noRequired = ['tag', 'nickName']; //不需要的字段
const formData = Object.keys(this.form)
  .filter(each => !noRequired.includes(each))
  .reduce((acc, key) => (acc[key] = this.form[key], acc), {});
powerdong commented 4 years ago
// 提取需要的数据
const formData= JSON.parse(
      JSON.stringify(this.form,["nickName","price"])
);
powerdong commented 4 years ago
// 覆盖数据
Object.assign(this.form, {
  tag: '商品1' 
}
powerdong commented 4 years ago
// 数据合并,如果字段相同,会覆盖前面表单数据字段的数值
 const query = { tenaId: '订单编号', id:'查询ID'}
   const formData = {
     ...this.form,
     query
   }