G
G
Grione2021-02-10 14:23:32
Vue.js
Grione, 2021-02-10 14:23:32

How to pass a condition and a function from computed to :class?

Just getting started with Vue JS.
I need to pass in :class a function call and a separate condition for the class.

<input :class="focus: isFocus, isOfTypeSearch">

export default {
  data() {
    return {
      isFocus: false,
    }
  },
  computed: {
    isOfTypeSearch() {
      return this.inputType === "search" ? "search" : ""
    },
  },
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Grione, 2021-02-10
@Grione

:class="{ search: isOfTypeSearch, focus: isFocus }"

Here is the solution. An empty string returns false ))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question