[Vuejs]-How to make Javascript syntax (condtional with if-else) more efficient to make it better and easier to understand (Vue.js)

0👍

Use nested arrays or objects.

const colorButtons = {
    field: 'status',
    1: {
        field: 'isCorrect',
        1: {
            field: 'isRemind',
            1: 'v-btn--outlined theme--light primary--text'
        },
        0: {
            field: 'isRemind',
            1: 'primary plain--text'
        }
    0: {
        field: 'isCorrect',
        0: {
            field: 'isRemind',
            1: 'v-btn v-btn--text theme--light success--text shadow-none',
            0: 'v-btn v-btn--text theme--light primary--text shadow-none'
        }
    }
}

getColorBtn(status, isCorrect, isRemind, textButton) {
    return colorButtons.?[status].?[iscorrect].?[isRemind] || 'primary';
}

Repeat this similarly for the other functions.

Leave a comment