JavaScript v-on click, add handler only if condition has been met

After some research the following suggestion by Mr. Evan You was found: https://github.com/vuejs/vue/issues/7349#issuecomment-354937350

So without any hesitation I gave it a try:

Component template

<template>
  <div v-on='{ click: dataType === `section` ? toggleSectionElements : null }'>
    ... magic 
  </div>
<template>

JS Logic

<script>
export default {
  name: `product-section`,
  props: [`section`, `sectionName`, `depth`],
  methods: {
    toggleSectionElements() {
      ... magic 
    }
  },
  computed: {
    dataType() {
      if (this.$props.section.sections || this.$props.depth === 0) {
        return `section`
      } else {
        return `element`
      }
    }
  }
}
</script>

But for described case it results in error during rendering:

[Vue warn]: Invalid handler for event "click": got null

Can someone please suggest what has been done wrong? :thinking:

Update
The way Data Model looks like:

DataModel: {
  mainSectionA: {
    sections: {
      sectionA: {
        sections: {
          elementA: { values: { ... } },     
          elementB: { values: { ... } }
        }
        values: { ... }
      }
      sectionB: {
        elementA: { values: { ... } },
        elementB: { values: { ... } }
      }
    },
    values: { ... }
  },
  mainSectionB: {
    sections: {
      elementA: { values: { ... } },
      elementB: { values: { ... } },  
      elementC: { values: { ... } },
      ... elements
    },
    values: { ... }
  }
}
Answer:1

Just change it to the below and it will work

v-on="condition ? { mouseover: handler } : {}"

or, if your handler is called mouseover

v-on="condition ? { mouseover } : {}"
Answer:2

Currently, I use PrestaShop, and I wanted to change the width of search box, but, when I change the width of search box to 650px, on desktop it's ok, but on mobile the search box is very long — not ...

Currently, I use PrestaShop, and I wanted to change the width of search box, but, when I change the width of search box to 650px, on desktop it's ok, but on mobile the search box is very long — not ...

Say you have the following array: const ab = ['a', 'a', 'b', 'b', 'b', 'a', 'b', 'b', 'a']; How would you change this array so that all the "b" items get grouped together, until you hit another "a". ...

Say you have the following array: const ab = ['a', 'a', 'b', 'b', 'b', 'a', 'b', 'b', 'a']; How would you change this array so that all the "b" items get grouped together, until you hit another "a". ...

I have a search bar with a toggle button above it. When I click the toggle button, it gradually changes the opacity. It works great, but it looks a bit clunky, because when I disable it (thus hiding ...

I have a search bar with a toggle button above it. When I click the toggle button, it gradually changes the opacity. It works great, but it looks a bit clunky, because when I disable it (thus hiding ...

I am using angularJS and bootstrap in a single project. When the web page is in the responsive mood , bootstrap navbar menu changes to toggler the menu responsive nav bar. The issue is when I use ...

I am using angularJS and bootstrap in a single project. When the web page is in the responsive mood , bootstrap navbar menu changes to toggler the menu responsive nav bar. The issue is when I use ...

  1. angular with bootstrap 4
  2. angular with bootstrap example
  3. angular with bootstrap tutorial
  4. angular with bootstrap or material
  5. angular with bootstrap 4 tutorial
  6. angular with bootstrap 3
  7. angular with bootstrap theme
  8. angular with bootstrap stackblitz
  9. angular with bootstrap 4 example
  10. angular with bootstrap template
  11. angular with bootstrap
  12. angular with bootstrap modal
  13. angular with bootstrap css
  14. angular with bootstrap table
  15. angular with bootstrap dropdown
  16. angular with bootstrap and jquery
  17. angularjs bootstrap
  18. angular with bootstrap grid
  19. angular with bootstrap datepicker
  20. angular with bootstrap sass