D
D
Dima2018-04-15 18:22:58
Vue.js
Dima, 2018-04-15 18:22:58

Vue.filter works in the first version and doesn't work in the second. What's wrong?

The demo has a character replacement filter, it works fine on the first version, but an error occurs on the second, what am I doing wrong?
And the second question: how best to implement so that the replacement of the character occurs in the same window where the text is written, and not duplicated on another element.
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2018-04-15
@qpz

The second one gives me an error, what am I doing wrong?

Trying to use a cut feature.
how best to implement so that the replacement of the character occurs in the same window

Use watch:
<textarea v-model="input"></textarea>
data: () => ({
  input: '',
}),
watch: {
  input(v) {
    this.input = v.split('1').join('2');
  },
},

Or listen to the input event:
<textarea v-model="input" @input="onInput"></textarea>

data: () => ({
  input: '',
}),
methods: {
  onInput() {
    this.input = this.input.split('1').join('2');
  },
},

E
Evgeny Kulakov, 2018-04-15
@kulakoff Vue.js

1. Add the input variable to the data section
2. Remove the extra {}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question