N
N
nastya_zholudeva2018-03-15 11:11:33
Vue.js
nastya_zholudeva, 2018-03-15 11:11:33

How to use v-model and value in one input?

There is

<input type="search" placeholder="Поиск" class="search__input" v-model="search" @keyup.enter="onSearchLineChanged(search)">
which sends the search value to the state (Vuex) on the onSearchLineChanged(search) event. In another component, on click, this search is replaced in state with a different value.
So I need that when this value is replaced (by clicking in the second component), it becomes value. for this input

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2018-03-15
@nastya_zholudeva

In the components, watch the value from vuex, something like this (yes, instead of different components, there are several instances of one, but I think the point is clear):

watch: {
  '$store.state.search'(val) {
    this.search = val;
  },
},

A
Alexander Aksentiev, 2018-03-15
@Sanasol

Well, put a getter from the state as a model.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question