SoFunction
Updated on 2025-04-03

vue select Second-level linkage Second-level instance of the first option value is selected by default

When the second-level linkage is used for selecting a country, if you want to select a country, the next city will select the first city by default. Then add a @change event to the country's select

<div class="inputLine">
  <span>Area</span>
  <select name="" v-model="countryName" @change="selectCountry">
  <option :value="item" v-for="(item,index) in area">
  {{}}
  <svg class="icon icon-arrow-bottom" aria-hidden="true">
  <use xlink:href="#icon-arrow-bottom" rel="external nofollow" rel="external nofollow" ></use>
  </svg>
  </option>
  </select>
  <select name="" v-model="cityName">
  <option :value="item" v-for="(item,index) in ">
  {{item}}
  <svg class="icon icon-arrow-bottom" aria-hidden="true">
  <use xlink:href="#icon-arrow-bottom" rel="external nofollow" rel="external nofollow" ></use>
  </svg>
  </option>
  </select>
 </div>
data
  countryName:{},
  cityName:"Please select a city",
  area:[
   {
   "country":"USA",
   "city":[
    "New York",
    "Los Angeles",
    "San Francisco",
    "Seattle",
    "Boston",
    "Houston",
    "San Diego",
    "Chicago",
    "other",
   ]
   },
   {
   "country":"Canada",
   "city":[
    "Vancouver",
    "Toronto",
    "Montreal",
    "other"
   ]
   },
   {
   "country":"Australia",
   "city":[
    "Sydney",
    "Melbourne",
    "other"
   ]
   },
   {
   "country":"Singapore",
   "city":[
    "Singapore"
   ]
   },
   /*{
    "country":"China",
    "city":[
    "Beijing",
    ]
    },*/
  ],

methods:

selectCountry(value){
  =[0];
  },

The above example of the second level linkage of vue select vue select the first option value by default is all the content I share with you. I hope you can give you a reference and I hope you support me more.