javascript - How can I reduce repetitiveness in Vue.js mixin with `computed` properties? -


here's code struggle make more dry:

# src/mixins/stateclassmixin.js  export default {   computed: {     statelabelclass: function () {       return {         'label-primary': this.ticket && this.ticket.attributes.state === 'new',         'label-info': this.ticket && this.ticket.attributes.state === 'pending',         'label-warning': this.ticket && this.ticket.attributes.state === 'on_hold',         'label-success': this.ticket && this.ticket.attributes.state === 'closed'       }     },      statepanelclass: function () {       return {         'panel-primary': this.ticket && this.ticket.attributes.state === 'new',         'panel-info': this.ticket && this.ticket.attributes.state === 'pending',         'panel-warning': this.ticket && this.ticket.attributes.state === 'on_hold',         'panel-success': this.ticket && this.ticket.attributes.state === 'closed'       }     }   } } 

as can see difference returned html class. it's either label-something or panel-something. i'm struggling extracting common bits new, separate function.


Comments

Popular posts from this blog

c# SetCompatibleTextRenderingDefault must be called before the first -

C#.NET Oracle.ManagedDataAccess ConfigSchema.xsd -

c++ - Fill runtime data at compile time with templates -