子组件代码
<template>
<div class="item" @click="gotoView($event)" >
<div class="iconfont-box">
<slot></slot>
</div>
<div class="title">Blog</div>
</div>
</template>
<script>
export default{
name: 'CubeNavItem',
props: ["id","title"],
methods: {
gotoView: function($event){
this.$emit('fatherGoToView',this.title,$event);
}
}
}
</script>
<style scoped>
</style>
父组件代码
<template>
<div class="window-bg">
<div class="box">
<cube-nav-item @fatherGoToView="goToView" v-for="item in navList" :key="item.id" :id="item.id" :title="item.title">
<span class="iconfont item-iconfont" v-html="item.iconfont"></span>
</cube-nav-item>
</div>
</div>
</template>
<script>
import CubeNavItem from "@/components/CubeNavItem";
export default{
name: 'index',
data(){
return {
navList: [
{id: 1,iconfont: '',title: 'Blog'},
{id: 2,iconfont: '',title: 'Music'},
{id: 3,iconfont: '',title: 'Dome'},
{id: 4,iconfont: '',title: 'Me'}
]
};
},
components: {
"cube-nav-item": CubeNavItem
},
methods: {
goToView: function(title,event){
alert(title);
console.log(event);
}
}
}
</script>
<style scoped >
</style>