[Vuejs]-Vue: Set active class – get current DOM element

4👍

Something like this… ?

<div id="app">
  <button :class="{'active': selected === 'a'}" @click="selected = 'a'">{{ message }}</button>
  <button :class="{'active': selected === 'b'}" @click="selected = 'b'">{{ message }}</button>
  <button :class="{'active': selected === 'c'}" @click="selected = 'c'">{{ message }}</button> 
</div>

Demo: https://jsfiddle.net/6gxz9y8q/


You can also use watchers to detect when values are changed. (demo), or run function as you did like (demo) or (demo), but don’t do something like (demo)

Leave a comment