为子组件设置原生事件

在子组件上加上.native即可使用子组件的原生点击事件,去掉.native点击事件无效

<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="vue.js"></script>
</head>
<body>
    <div id="app">
        <h2>{{message}}</h2>
        //.native时间
        <my-button @click.native="test"></my-button>
    </div>

    <script>
        let myButton = {
            template:'<button>子组件点击时间</button>'
        }
        let app = new Vue({
            el:'#app',
            data:{
                message:'hello'
            },
            components:{
                myButton
            },
            methods:{
                test:function(){
                    this.message = '我是子组件'
                }
            }
        })
    </script>
</body>
</html>```
posted @ 2021-01-28 09:10  HF10  阅读(73)  评论(0)    收藏  举报