先上代码

//父组件
  <hj-subjects v-if="showHjSubect" :list="subjectsList" @getHjSubjects="getHjSubject"></hj-subjects>
  
import HjSubjects from "@/components/HjSubjects";

export default {
  name: "YhkmUp",
  components: {
    HjSubjects,
  },
	data() {
   	 	return {
		    showHjSubect:false,
		 }
	 }
 },
 methods:{
     getHjSubject(data){
      
    },
      hjSubects(){
      this.showHjSubect =true;
    },
 }

//子组件
	export default {
		name: "HjSubjects",
		components: {},
		props: {
			showHjSubect: {
				type: Boolean,
				default: false,
			},
		},
		methods: {
		    getList() {
		    console.log(this. showHjSubect);//一直是false,不随父组件的值改变而改变
 			}
  	  },
  	  }

解决方案:
父组件中 showHjSubect绑定方法

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐