V模型的Vue自定义组件

时间:2020-06-05 14:54:01

标签: vuejs2 vue-component

我有一个使用自定义组件构建的表单,可供我们使用。 注意:我无权访问自定义组件,添加@input解决方案对我不起作用。 我有什么方法可以在不更改组件的情况下从自定义组件中获取价值?

  <section class="container__content">
   <div>Details</div>
      <div class="personal-info">
        <textfield type="text" label="Name" placeholder="Shweta"></textfield>
         <textfield type="text" label="ID" placeholder="sm1234"></textfield>
       </div>

1 个答案:

答案 0 :(得分:0)

如果我对您的理解正确,则需要$ refs对象。 https://vuejs.org/v2/guide/components-edge-cases.html#Accessing-Child-Component-Instances-amp-Child-Elements 基本代码示例:

<template>
<child ref="childA"></child>
<child ref="otherCHild></child>
</template>

this.$refs.childA.something
this.$refs.otherCHild.something

两个$ refs变量将是它们各自的子对象中something变量中包含的值。

我在utils库中使用它来监视希望触发父级操作的更改(例如监视上传完成或错误)