zhx119

Vue 中select option默认选中的处理方法

在做泰康项目的时候有个需求就是要给select默认选中的样式我的处理方法有两个

1.直接将默认值给  selectedOption

<select v-model="selectedOption">
<option v-for="option in options" :value="option">{{option.city}}</option>
</select>
js
data ()
{
return {
selectedOption:{cityCode:0,city:"北京"},
selectedOption:{},
options:[
{
cityCode:0,
city:"北京"
},{
cityCode:1,
city:"上海"
},{
cityCode:2,
city:"天津"
},{
cityCode:3,
city:"重庆"
}
]
}
}
2.在created生命期函数上给selectedOption赋值给当前需要默认的值
created (){
this.selectedOption = this.options[1]
}
发表于 2018-11-29 14:21  zhx119  阅读(2841)  评论(0编辑  收藏  举报
 

分类:

技术点:

相关文章:

  • 2021-10-17
  • 2021-11-21
  • 2021-11-21
  • 2021-10-20
  • 2021-10-15
  • 2021-11-11
猜你喜欢
  • 2021-09-10
  • 2021-09-10
  • 2021-09-10
  • 2021-09-10
  • 2021-11-21
  • 2021-09-10
相关资源
相似解决方案