vue方法中传递dom对象示例

<div id="app">
    <input type="text" v-on:keyup="onlyNum($event)">
</div>

<script>
new Vue({
    el:"#app",
    methods: {
        onlyNum: function (event){
            event.target.value=event.target.value.replace(/[^\d]/g,'');
        }
    }
})
</script>

 相当于:

<div id="app">
    <input type="text" onkeyup="onlyNum(this)">
</div>

<script>
        function onlyNum(obj){
            obj.value = obj.value.replace(/[^\d]/g,'');
        }
</script>

 js 原生代码的 “this” 相当于vue中 “event.target” 。

猜你喜欢

转载自www.cnblogs.com/qingsong/p/11575485.html
今日推荐