VUE关于父组件实时监听子组件的方法

VUE关于父组件实时监听子组件的方法

  1. 利用vuex来解决
  2. 利用子组件监听(watch)触发父组件($emit)方法来解决

方法一可以参照这个,应该可以实现(反正我没用)
方法二

//子组件
<template>
	<div class="rdo-grp">
		<template v-for="item in currentListKey">
			<input :id="currentValue[item]+'label'" type="radio" :name="radioName" v-model="radioValue" :value="item" :key="currentValue[item]+'input'">
			<label :for="currentValue[item]+'label'" :key="currentValue[item]"><span></span><span>{{item}}-{{currentValue[item]}}</span></label>
		</template>
	</div>
</template>
<script>
	export default {
		name: 'radioComponent',
		props: ["currentValue"],
		data () {
			return {
        radioValue:"1",
        radioName:this.currentValue[Object.keys(this.currentValue)[0]],
        currentListKey:Object.keys(this.currentValue),
			};
		},
		created(){
    },
    watch:{
      "radioValue":function(newValue,oldValue){
        this.$emit('childFn', newValue);
      }
    },
</script>
<template>
    <div>
      {{radioFlag}}   
      <ui-radio :currentValue="importTp" ref="uiRadio1" @childFn="changFlag"></ui-radio>
    </div>
</template>
<script>
export default {
  props: ["link_unique_trade_datas"],
  data() {
    return {
      addParams:{
        fileName:"",
        file:[],
      },
      radioValue:"",
      importTp:{
        "1":"文件导入",
        "2":"数据源导入",
      },
      importMtd:{
        "1":"覆盖导入",
        "2":"存在忽略导入",
        "3":"精确导入"
      },
      radioFlag:"1",
    };
  },
  methods: {
    changFlag(radioValue){
      this.radioFlag = radioValue;
    },
  }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值