vue-api-query icon indicating copy to clipboard operation
vue-api-query copied to clipboard

How to add default attributes

Open ajcastro opened this issue 3 years ago • 0 comments

What is the correct way of adding default attributes? Maybe we can also include in the documentation. Currently this is how I did it. Also please let me know if my solution is valid or correct. Thanks!

export default class Model extends BaseModel {
  constructor(...attributes) {
    super()

    if (attributes.length) {
      Object.assign(this, this.defaultAttributes(), ...attributes)
    }
  }

  defaultAttributes() {
    return {}
  }
}


export default class User extends Model {
  defaultAttributes() {
    return {
      selected: false // useful for checkbox or selection state
    }
  }
}

ajcastro avatar Sep 30 '21 11:09 ajcastro