使用vue.js的select组件,通过api获得数据,并选中一个值,结果select显示的是id而不是中文。
element-ui的select组件
<el-select v-model="selected" placeholder="请选择" class="selection" @change="change">
<el-option
v-for="item in games"
:key="item.id"
:label="item.title"
:value="item.id">
</el-option>
</el-select>
data数据:
return {
games: [{}],
selected: this.$store.getters.game_id,
}
api请求,从vuex中取出id,并选中。
created() {
const game_id = this.$store.getters.game_id
getGamesByUid().then((response) => {
this.games = response.message
this.selected = this.$store.getters.game_id
}
selected和games里的value要一样才能默认选中的