0👍
You can use either computed property or methods to solve this.
With computed property:
...
computed: {
collapsed() {
return this.foo && this.bar
}
}
...
<div class='content' :class='{ collapsed }'>
...
</div>
With methods:
...
methods: {
computeCollapsed(inputs) {
return inputs.every(x => x)
}
}
...
<div class='content' :class='{ collapsed: computeCollapsed([foo, bar]) }'>
...
</div>
In comparison, a method invocation will always run the function whenever a re-render happens.
Source Computed Caching vs Methods
If you only have a few sections and the number of sections if fixed, you should use computed property over methods.
- [Vuejs]-How i can swap the selected options of two bootstrap-vue multiple select boxes?
- [Vuejs]-Multiple requests from different components in Vue – best practice
0👍
I ended up making a clone of the initial data and props that was not reactive, and using that to set up the initial status.
- [Vuejs]-Manage undefined value of an object
- [Vuejs]-How to get the API response into my listrendering in vue 3?
Source:stackexchange.com