Vue——给组件绑定原生事件

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>给组件绑定原生事件</title>
        <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    </head>
    <body>
        <div id="root">
            <child @click.native="handleClick"></child>
        </div>
        <script type="text/javascript">
            Vue.component('child',{
                template:'<div>Child</div>'
            })

            var vm = new Vue({
                el:'#root',
                methods:{
                    handleClick(){
                        alert('Click')
                    }
                }
            })
        </script>
    </body>
</html>

 

posted @ 2019-10-28 15:39  嘆世殘者——華帥  阅读(120)  评论(0编辑  收藏  举报