下拉菜单变化时,父组件给子组件传递,实现页面变化
父组件
<el-dropdown @command="handleCommand">
<el-dropdown-menu slot="dropdown">
<el-dropdown-item v-for="(subItem, i) in list[1].children" @click.native="toPages(subItem.name)"
:command="i">{{
subItem.navItem }}</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
<script>
created() {
this.handleCommand();
},
methods: {
handleCommand(command) {
this.$emit('child-click', command);
},}
</script>
子组件
<div>
<CommonHeader @child-click="handleCommand" />
<div>
<script>
handleCommand(data) {
if(data == 1){
this.selectPage = "page1"
} else{
this.selectPage = "page2";
}
console.log(this.selectPage)
this.getDataList(this.selectPage)
}
</script>