【问题标题】:Vue-js reactive element affects a different elementVue-js 反应元素影响不同的元素
【发布时间】:2021-07-07 20:25:02
【问题描述】:

我们有一个包含许多组件的 vue-js 页面 (@vue/cli 4.5.6),大部分都可以正常工作。一个组件正在做我不明白的事情:有两个单选框,一个在页面顶部,一个在底部。它们似乎完全不相关;这是一个

    <template v-for="qSection in qSections">
    ...
      <!--- loop to output individual questions here --->
      <tr v-for = "question in qSection.questions">
        <td>
          {{ question.txt }}
          <div v-if="question.incf">
            <br/>
            <textarea rows="2" cols = "80" :name= "question.cmt" 
              v-model="question.cmt" placeholder = "Comments here"
              class="hideOnPrint"
            />

            <div class="print-only"> {{ question.cmt }} </div>
          </div>
        </td>
        <!-- okay, three more tds to hold radio box-->
        <template v-for="icnt in [1,2,3]">
        <td>
            <label v-if="question.otherAns" class="other-ans-label">
              {{ question.otherAns[icnt].txt }}
            </label><br/><br/>
            <input type = "radio" :name= "question.quesn" :value = "(icnt%3)"
              v-model="question.answer"/>
        </td>
        </template>
      </tr>

这是另一个

        <template v-if="section.otype1 != 'Laboratory'">
          <div class="hideOnPrint">
            <input type = "radio" :name = "section.accept" :value="1"
              v-model="section.accept"
            >
              {{acceptPhrase}}
            </input>
            <br/><br/>
            
            <input type = "radio" :name = "section.accept" :value="0"
              v-model="section.accept"
            >
              Investigation is incomplete. See comments.
            </input><br/><br/>
          </div>
        </template>

所以发生的事情是单击底部区域中的单选按钮(仅适用于 value="1")un-单击顶部区域中的单选按钮(question.answer,以任何一个为准)被选中)。 根据开发者工具中的 Vue 应用程序,顶部区域数据仍然设置为:questions.answer = 2,比如说。事实上,如果我在那里将它设置为 1 并返回为 2,则该单选框会被正确地重新检查。

这是怎么发生的,我应该改变什么来解决它?或者我应该怎么做才能诊断它。谢谢!

我想举一个可行的例子,但不知道怎么做;页面的其余部分有很多部分。

【问题讨论】:

    标签: vue.js vue-component


    【解决方案1】:

    哦,哇:我意识到我的错误了。就是代码中的那些行,
    :name="question.quesn"

    :name = "section.accept"。
    这些将单选框的名称设置为这些字段的值。它们最终都等于 1,因此两个单选框成为一个单选框。单击一个会关闭另一个。 根本不应该使用名称; v-model 完成了这项工作。

    【讨论】:

      猜你喜欢
      • 2017-01-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-11
      • 1970-01-01
      相关资源
      最近更新 更多