The vue elementUI select drop-down box sets the default value

Regarding the failure to assign the default value of the element select box, pay attention to two points:

The data in the v-model is different from the data type of the traversed value. ! ! ! !
(Example: the type of item.provinces is number, and the type of province is String. Different types lead to unsuccessful assignment.)
The sequence of traversing data and assignment must ensure that data is traversed first and then assigned. ! ! !
 

To set a default value for the select drop-down box, just  set v-model the bound value   to be the same as the value you want to option select  .value

Code below:

html part code:

<el-select v-model="valuetype"  @change="changetype">
    <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
    </el-option>
</el-select>
export default {
        data() {
            return {
                options: [
                    {
                        value: 'all',
                        label: '全部'
                    },
                    {
                        value: 'model',
                        label: '型号'
                    },
                    {
                        value: 'machine',
                        label: '机器'
                    }
                ],
                valuetype: 'all',
            };
        },
     }

Guess you like

Origin blog.csdn.net/qq_59747594/article/details/125462635