先上代码
//父组件
<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绑定方法