亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在我觸發任何操作之前觸發 Vue 選擇更改事件

在我觸發任何操作之前觸發 Vue 選擇更改事件

飲歌長嘯 2022-06-09 11:21:43
我有一個 Vue 應用程序,它似乎在我更改選擇之前觸發了更改事件,最近嘗試了 @input,但仍然發生同樣的事情(如下所示)請注意,我已經嘗試過 @change 和 @input 并且在加載控件時事件仍然會觸發現在這在我對組件范圍進行 css 更改之前就可以工作了,這樣它就不會影響周圍的 css。但無法理解為什么這會產生任何影響。有誰知道為什么在添加選項標簽和內容時會觸發更改事件?<div class="form-group" :class="{formError: errors.has('formSection')}">    <label for="formSection">Section*</label>    {{ formModel }}    <select        v-model="formModel.idSection1"        class="form-control"        id="formSection"        name="formSection"        @input="onChangeSectionLevel1">        <option v-for="sectionLevel1 in formModel.sectionLevel1"                                     v-bind:value="sectionLevel1.value"                                     v-bind:key="sectionLevel1.id">                                    {{ sectionLevel1.value }}        </option>    </select>                                    <span v-if="errors.has('formSection')">This field is required</span></div>一旦我添加了遍歷項目的選項標簽,就會調用 onChangeSectionLevel1 函數。我認為這可能是 vee-validate 但把它拿出來仍然會發生。methods: {   onChangeSectionLevel1() {      alert("changed");      ...   }}更新:我注意到,如果我打印出正在綁定的對象,我會得到這個缺少idSection1項目。{    "idSection2": null,    "idSection3": null,}如果我然后只放一個如下所示的虛擬選項,那么我可以看到我的 3 個數據項,包括 idSection1 如果我使用 v-for<select    v-model="formModel.idSection1"    class="form-control"    id="formSection"    name="formSection"    @change="onChangeSectionLevel1">    <option>Hello World</option></select>數據項仍然列出了 idSection1{    "idSection1": null,    "idSection2": null,    "idSection3": null}提前謝謝了
查看完整描述

1 回答

?
慕斯709654

TA貢獻1840條經驗 獲得超5個贊

不是真正的答案,但上面的代碼是在 js fiddle 中找到并按預期工作


https://jsfiddle.net/andrewp37/a4obkhd5/1/


代碼:


<div id="app">

  <label for="formSection">Section*</label>

  {{ formModel }}

  <select

          v-model="formModel.idSection1"

          class="form-control"

          id="formSection"

          name="formSection"

          @change="onChangeSectionLevel1">

    <option v-for="sectionLevel1 in formModel.sectionLevel1" 

            v-bind:value="sectionLevel1.value" 

            v-bind:key="sectionLevel1.id">

      {{ sectionLevel1.value }}

    </option>

  </select>  

</div>


new Vue({

  el: "#app",

  data: {

    formModel: {

        idSection1: null, 

      sectionLevel1: [

        {

                    id: 1, 

          value: "Section 1"

        }

      ]

    }

  },

  methods: {

    onChangeSectionLevel1() {

     alert("changed");

    }

  }

})

我注意到添加了很多斷點后,模型會在頁面安裝后被替換。


查看完整回答
反對 回復 2022-06-09
  • 1 回答
  • 0 關注
  • 160 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號