为子组件设置原生事件
在子组件上加上.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>```

浙公网安备 33010602011771号