In the vue project, how to make the value of the drop-down box default to the smallest value in the array obtained by the query background?

is written, thank you @ hfhan

<el-select v-model="value">
    <el-option
      v-for="item in gameStatusList"
      :key="item.value"
      :label="lang=="zh" ? item.nameCn : item.nameEn"
      :value="item.value">
    </el-option>
  </el-select>
  
  watch:{
      gameStatusList(data,oldData){
        if (oldData.length===0&&data.length>0){
          this.value=1//
        }
      }
    },

the value of the drop-down box in the vue project is the smallest value in the array obtained by the query background by default.

requirements such as problems,

is for example, < select v val modelling values val" >
the initial value of val is the smallest value in the array, but the later changes of val have nothing to do with the array. Only when the page loads, when assigning the initial value to the array is related to the array, there will be no relationship in the future. You can no longer change the value of the array because of the change of the array

.

when the project is loaded, execute the actions, of vuex to execute the query and assign a value to an array of state in store.
then if I use the property in v-model data to assign a value to the property in data in the component created method, when the component created, the array is still empty, so the array cannot be traversed, so the assignment fails.

if I use the calculation property, I don"t understand what happens when the v-model calculates the property. Whether its value is based on the drop-down box or get

Mar.02,2021

isn't select bound with a value VMI model = "val" . The state array is listened in watch. When the array changes, find the minimum value and assign it to val


first of all, you need to find the smallest number from the array given in the background, and then bind it to select

.
Menu