TypechoJoeTheme

香草物语

统计
登录
用户名
密码
/
注册
用户名
邮箱
输入密码
确认密码

Vue中文输入法实时更新数据值

Laughing博主
2021-02-21
/
0 评论
/
893 阅读
/
79 个字
/
百度已收录
02/21
本文最后更新于2024年03月18日,已超过185天没有更新。如果文章内容或图片资源失效,请留言反馈,我会及时处理,谢谢!

使用v-model是,如果是用中文输入法输入中文,一般在没有选定词组前,也就是在拼音阶段,Vue是不会更新数据的,当敲下汉字时才会触发更新,如果希望总是实时更新,可以用@input来替代v-model

<html>

<head>
    <title>Vue学习</title>
    <script src="vue.js"></script>
</head>

<body>

    <div id="app">
        <input type="text" v-model="message" placeholder="请输入">
        <input type="text" placeholder="实时更新" @input="handleInput">
        <p>
            {{message}}
        </p>
    </div>

    <script type="text/javascript">
        var app = new Vue({
            el: '#app',
            data: {
                message: ''
            },
            methods:{
                handleInput:function(e){
                    this.message=e.target.value
                }
            }
        })
    </script>
</body>

</html>
朗读
赞(0)
赞赏
感谢您的支持,我会继续努力哒!
版权属于:

香草物语

本文链接:

https://www.xiangcaowuyu.net/web/vue-chinese-input-method-real-time-update-data-value.html(转载时请注明本文出处及文章链接)

评论 (0)
  1. along 闲逛
    Windows 10 · Google Chrome

    ganxfenx感谢分享

    2018-10-15 回复