vue 利用父组件实现子组件一调用子组件二的方法

在父组件import引入 子组件
<collapseOption
      ref="collapse"
    ></collapseOption>
    <tipsDialog
      :show="isShow"
      :msg="msg"
    ></tipsDialog>
methods: {
    handle() {
      const oneI = localStorage.getItem('oneI')
      const twoE = localStorage.getItem('twoE')
      this.$refs.collapse.selected(oneI, twoE, 1)
    }
}

子组件一
 <div @click="selected(index,num,val.other)">子组件1</div>
selected(i, e, other) {
      localStorage.setItem('oneI', i)
      localStorage.setItem('twoE', e)
}

子组件二 【调用子组件一的方法】
cancel() {
      this.$parent.handle()//调用子组件1的方法
      this.$emit('show')
}


========================================================
for循环渲染多个输入框input,输入时会全部的input都输入或清除,v-model使用数组的形式
    <van-field
      v-model="valOtherName[index]"
        ref="field"
        @input="getInput"
        @focus="getFocus"
        placeholder="請輸入餐廳名稱"
    />



 

posted @ 2022-10-26 15:10  多喝热水,早点睡觉  阅读(137)  评论(0编辑  收藏  举报