The problem of trinomial operation in vuex

if you use the trinomial operator in a project, eslint will report an error. How else can this trinomial operation be written?

data () {
    return {
      open: false,
      currentTab: false,
      isFolder: this.model.children && this.model.children.length ? true : false
    }
  },
Mar.21,2021

well, if you need a Boolean value, there is no need for trinomial operation to achieve the effect

data () {
    return {
      open: false,
      currentTab: false,
      isFolder: this.model.children && this.model.children.length // true or false
    }
}

if you must use it

data () {
    return {
      open: false,
      currentTab: false,
      isFolder: (this.model.children && this.model.children.length) ? true : false
    }
}

add that the operation priority of & & is lower than that of ?: , and the length attribute on the right is not the bool expression

.
clipboard.png
no, take


then you can turn this off in .eslintrc.js and you will not make a mistake


feel that it will be better to write this into the calculation attribute

.
Menu