R
R
richrichwx2018-09-22 04:07:38
Vue.js
richrichwx, 2018-09-22 04:07:38

How to switch between input and text?

It is necessary to make an input where the full name is entered. After entering, the input disappears, but the entered text remains and a checkmark appears next to it.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-09-22
@richrichwx

The two properties are the user input value and the state (input activity). v-ifEither input or span ( / v-else) is displayed depending on the state . Something like this :

<input v-if="input" v-model="name" @keypress.enter="onEnter">
<span v-else v-text="name" @click="onClick"></span>

data: () => ({
  name: '',
  input: true,
}),
methods: {
  onEnter() {
    if (this.name) {
      this.input = false;
    }
  },
  onClick() {
    this.input = true;
  },
},

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question