1:修饰符语法
<template>
<div>
<back-top @click.native="backClick"></back-top>
</div>
</template>
<script>
import BackTop from "components/content/backTop/BackTop.vue"
export default {
components: {
BackTop
},
methods:{
backClick(){
console.log('backtop组件被点击了')
}
}
}
</script>
<style>
</style>
@click只能监听原生标签的点击,@click.native可以监听组件的点击
2.组件外面套一层div
<template>
<div>
<div @click="backClick">
<back-top></back-top>
</div>
</div>
</template>
<script>
import BackTop from "components/content/backTop/BackTop.vue"
export default {
components: {
BackTop
},
methods:{
backClick(){
console.log('backtop组件被点击了')
}
}
}
</script>
<style>
</style>