@change method is taking the previeous selected value of select box

纵饮孤独 提交于 2020-01-25 10:14:22

问题


I have a country Id which is bind by v-model. Whenever I change the select box i call an event @change which calls a method country_change that will fetch the value of the states belongin to that perticular country id. The porblem is that the states which I am fetching belongs to the prevously selected country id, not the country id which is currently selected. Seems like as if the @change method is running before the v-model bind value of country id is being changed.


     <select class="custom-select form-control" id="country" name="country" v-model="country" @click="country_change">
        <option value="">Select Country</option>
        @foreach($countries as $country)
        {
          <option value="{{ $country->id }}" >{{ $country->name }}</option>
        }
        @endforeach
      </select>

  data: function () {
    return {
      country: '101',
      states: null
    }
  },

  methods: {
    country_change: function () {
      axios
      .get('/states/'+this.country)
      .then(res => this.states = res.data )
      .catch(err => console.error(err));
    }
  }

回答1:


I figured out the problem was with the vue.js devtool. It was showing the results corresponding to the previously select value of select-box.



来源:https://stackoverflow.com/questions/59692303/change-method-is-taking-the-previeous-selected-value-of-select-box

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!