The cause of

You need to create a province selector for the receiving address. The existing address information needs to be displayed. After the display is successful, click the selector to enter the current value location.

<van-picker
  show-toolbar
  title="Select province"
  value-key="name"
  default-index="{{ state_index }}"
  columns="{{ stateColumns }}"
  bind:confirm="onStateConfirm"
  bind:cancel="onStateClose"
/>
Copy the code

Setting the value of default-index to state_index has no effect.

If you want to change the default value dynamically, use setColumnIndexAPI as follows:

<van-picker
  show-toolbar
  title="Select province"
  class="state_default"
  value-key="name"
  columns="{{ stateColumns }}"
  bind:confirm="onStateConfirm"
  bind:cancel="onStateClose"
/>
Copy the code
// Display the student's province information
this.data.stateColumns.forEach((item, index) = > {
  if (item.id === this.data.state_id) {
    
    this.setData({
      state_index: index,
      state_name: item.name
    })
    const picker = this.selectComponent(".state_default"); // Get the component instance
    picker.setColumnIndex(0, index); }})Copy the code

Unfortunately, still invalid !!!!

After a long search, it turns out that dynamic indexing only works when the picker is turned on.

Like this:

<van-picker
  show-toolbar
  title="Select province"
  class="state_default"
  value-key="name"
  columns="{{ stateColumns }}"
  bind:confirm="onStateConfirm"
  bind:cancel="onStateClose"
/>
Copy the code
// Province select open
provincesSelect () {
  this.setData({
    pickerShow: true
  })
  const picker = this.selectComponent(".state_default"); // Get the component instance
  picker.setColumnIndex(0.this.data.state_index);
},
Copy the code

Perfect solution!