我要做的功能是,点击选择全部后,获取所有商品的id为一个数组,然后点击选择完成,子组件向父组件传值这个id数组,并且这个选择全部的多选框从选择状态改为未选择状态
template中选择全部的代码:
<el-table-column
width="100">
<template slot="header">
// data中allShow默认值是false
<el-checkbox :checked="allShow" @change="clickCheckAll" :label="allShow" class="checkAllTxt" >选择全部</el-checkbox>
</template>
<template slot-scope="{row}">
<el-checkbox-group v-model="checkList">
<el-checkbox :label="row.id" @change="checkChange($event,row)"></el-checkbox>
</el-checkbox-group>
</template>
</el-table-column>
点击选择全部的事件代码:(子组件)
async clickCheckAll(e){
console.log('e',e);
if(!this.allId.length) {
const data = await getAllData('alldata/all')
data.data.data.forEach((val,index) => {
this.allId.push(val.id)
})
this.$nextTick(() => {
this.allShow = true
})
} else {
this.allId = []
this.$nextTick(() => {
this.allShow = false
})
}
console.log('this.allId',this.allId);
}
点击选择完成事件:(父组件)
// 当tabs是折扣优惠时
disposeDiscount(){
if(this.$refs.tablesGoods.allShow == true) {
let allid = this.$refs.tablesGoods.allId
this.$refs.discount.goodsData = allid
this.$refs.tablesGoods.allShow = false
// this.$nextTick(() => {
// this.$refs.tablesGoods.allShow = false
// })
console.log('sssss',this.$refs.tablesGoods.allShow);
} else {
let tableData = this.$refs.tablesGoods.tableData
let checkList = this.$refs.tablesGoods.checkList
let checkGoodsData = []
console.log('checkList-----11111111111',checkList);
tableData.forEach((val,index) => {
checkList.forEach((cval,cindex) => {
if(cval == val.id) {
checkGoodsData.push(val)
}
})
})
this.$refs.discount.goodsData = checkGoodsData
}
},
为什么我一直实现不了啊,是哪里出现了问题,我有在父组件修改子组件的allshow的值,打印看也修改成功了,为什么一直没有渲染成功啊