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

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -