1、父組件向子組件傳值:
父組件
父組件中通過v-bind:參數(shù)名=“參數(shù)名”仑氛,向子組件中傳遞參數(shù)
<el-dialog title="渠道商已授權(quán)車場" :visible.sync="parkingDialogVisible" :close-on-click-modal="false" :modal-append-to-body="false">
<project-authorization-component v-bind:channelId="channelId"></project-authorization-component>
</el-dialog>
子組件
在子組件中用watch來監(jiān)聽參數(shù)值的變化乙埃,一旦參數(shù)值變化锯岖,就會觸發(fā)watch監(jiān)聽的方法介袜。
export default {
props: ['channelId'],
watch: {
channelId:{
handler(newVal,oldVal){
this.channelIdB = newVal;
this.queryChannelParkList(1)
},
deep: true,
immediate: true,
},
},
.......
data() {
return {
channelIdB:'',
......
}
}
}
2出吹、子組件向父組件傳值
子組件
如果this.parent.$emit();
this.$emit('getwithholdinfo',{'itemCode':this.code,'itemName':this.name})
父組件
在父組件中創(chuàng)建@getwithholdinfo="getwithholdinfo"捶牢,與子組件傳遞的方法名相同鸠珠,
<el-dialog title="選擇代扣類型" :visible.sync="selectWithholdDialogVisible" :close-on-click-modal="false">
<select-withhold-component v-bind:refreshDialog="refreshDialog" @closedialog="closedialog" @getwithholdinfo="getwithholdinfo"></select-withhold-component>
</el-dialog>
然后加派,父組件中g(shù)etwithholdinfo方法的實現(xiàn)如下:
//獲取代扣方式name跳芳、code
getwithholdinfo:function(params){
this.dataForm.name=params.itemName;
this.dataForm.code=params.itemCode;
this.selectWithholdDialogVisible=false;
},