相关文章推荐
热心肠的钱包  ·  获取函数名 - CSDN文库·  4 月前    · 
冷静的马克杯  ·  awk输出到变量[重复]。·  1 年前    · 
稳重的肉夹馍  ·  C# ...·  1 年前    · 
年轻有为的山羊  ·  Flutter ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

How can I use an if statement inside either a v-bind, v-on or @ click to handle which function gets run?

What I have right now that only sort of works is this (the if statement is in shorthand javascript):

        <li v-for="entry in entries.entries"><button type="button" @click="entry.entries?openSub($event):'entry.action'">{{entry.title}}</button>

So basically, if the buttons list item has sub entries inside it the button should trigger the function that adds the submenu-active class to the list item, and if the list item the button is in does not have any sub entries it should run whatever function has been assigned to the button.

I say it sort of works because it does run the openSub($event) part correctly, but it neither runs nor even adds the function that's supposed to be run if there are no entries.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.