Click method for vue child components. The parent component cannot accept or change the class.

1. The child component has a "@ click=" collapseStatus click event, and then the "v left230" binding class=" {"left230": changeleft," left64":! changeleft} "in the parent component changes the width with the click event,
but the click does not respond. The width has always been the default left230 width
I don"t know why

< hr >

2. The code is as follows:

subcomponents

<div class="iscollapse fl"  @click="collapseStatus">
    <i class="iconfont magicship-daohanglanmoshi02"></i>
</div>

<script>
//import Bus from "Bus.js";
export default {
    name: "Topnav",
    data () {
        return {
          changewidth: true,
        }
    },
    methods: {
         collapseStatus: function () {//
             this.$bus.$emit("collapseBtnClick" );
             this.$emit("ShowChild",this.changeleft);
            this.changewidth = !this.changewidth;
        },
    },



}
</script>

parent component

<template>
    <el-container>
      <el-aside width="auto"><Leftnav></Leftnav></el-aside>
      <el-container>
        <el-header height="50px"><Topnav></Topnav></el-header>
        <el-main v-bind:class="{ "left230" : changeleft, "left64": !changeleft}" 
                  v-on:ShowChild="ShowChild"
                  
                 >Main</el-main>
      </el-container>
    </el-container>

</template>

<script>
import Topnav from "../components/Topnav.vue"
import Leftnav from "../components/Leftnav.vue"
export default {
      name: "Index",
      components:{
        Topnav,    
        Leftnav,
    },
    data () {
        return {
             changeleft: true,
        }
    },
    methods: {
        ShowChild: function (changeleft) {
             //this.changeleft = !this.changeleft
             console.log("1")

         }
    }
    

}
</script>

3. Problem: console.log ("1") does not respond. It seems that ShowChild did not proceed, but the child component can click to switch to the child component, but the parent component is not allowed ,

Jul.04,2022

your subcomponents changeleft are not defined.


1. First of all, your sub-components should be the two introduced, the monitoring is not on the sub-components at all.
2. Is the changeleft of the subcomponent defined?
3. The template of the sub-components is not written?
4. Why do the arguments passed by the function use this, and the name should not be the same.
5. There are too many code problems. It is recommended to go over the official document


first. It turns out that I have made a mistake in listening to the event. If I correct it, I can

.
Menu