使用中文输入问题计算的 Vue 2 触发器
vue 2 trigger computed with chinese input issue
我正在使用 vue2 来开发我的项目。
我发现计算出来的属性只会在我们keyup/keydown输入中文的时候触发。
(ex: ㄨㄛˇ => 我
格式化为word时只会触发1次不会触发3次)
这不像纯粹的 javascript 事件。对吗!?
你说得对!来自文档 (https://vuejs.org/v2/guide/forms.html):
For languages that require an IME (Chinese, Japanese, Korean etc.), you’ll notice that v-model doesn’t get updated during IME composition. If you want to cater for these updates as well, use input event instead.
试试这个:
new Vue({
el: '#app',
data: {value: ''}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.1.4/vue.js"></script>
<div id="app">
<p>The value is: {{value}}</p>
<input v-on:input="value = $event.target.value"/>
</div>
我正在使用 vue2 来开发我的项目。
我发现计算出来的属性只会在我们keyup/keydown输入中文的时候触发。
(ex: ㄨㄛˇ => 我
格式化为word时只会触发1次不会触发3次)
这不像纯粹的 javascript 事件。对吗!?
你说得对!来自文档 (https://vuejs.org/v2/guide/forms.html):
For languages that require an IME (Chinese, Japanese, Korean etc.), you’ll notice that v-model doesn’t get updated during IME composition. If you want to cater for these updates as well, use input event instead.
试试这个:
new Vue({
el: '#app',
data: {value: ''}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.1.4/vue.js"></script>
<div id="app">
<p>The value is: {{value}}</p>
<input v-on:input="value = $event.target.value"/>
</div>