search

Home  >  Q&A  >  body text

javascript - vue uses v-for to implement the drop-down box of Are You Hungry?

<el-dropdown @command="handleCommand">
                    <el-button type="primary">
                        {{dropvalue}}<i class="el-icon-caret-bottom el-icon--right"></i>
                    </el-button>
                    <el-dropdown-menu slot="dropdown">
                        <el-dropdown-item v-for="(item,index) in dropDowns" command="item.index">{{item.name}}</el-dropdown-item>
                    </el-dropdown-menu>
                </el-dropdown>

If you want to get the index in the current loop, "1, 2, 3···" instead of the "item.index" string, the incoming command="item.index" will not work. The display effect is as follows

The command command here is the default if you are hungry. If you use an enumeration drop-down box, such as:
<el-dropdown-item command="a">Golden Cake</el-dropdown- item>At this time, the value can be obtained as a.

迷茫迷茫2771 days ago596

reply all(2)I'll reply

  • 習慣沉默

    習慣沉默2017-05-19 10:37:51

    :command="item.index"

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-05-19 10:37:51

    The above is correct haha

    reply
    0
  • Cancelreply