<template>
  <view class='container'>
    <picker mode='selector' :range='selector' @change='onSelectorChange'>
      <view class='picker'>
        {{selector[selected]}}
        <image src='/static/images/arrow.png'></image>
      </view>
    </picker>
  </view>
</template>
<script>
export default {
  data() {
    return {
      selector: ['选项一', '选项二', '选项三'],
      selected: 0
    }
  },
  methods: {
    onSelectorChange(e) {
      this.selected = e.target.value
      console.log('选择了第' + (this.selected + 1) + '个选项')
    }
  }
}
</script>
<style>
.container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background-color: #f5f5f5;
}
.picker {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px;
  border: 1px solid #ccc;
  border-radius: 5px;
  background-color: #fff;
  font-size: 16px;
}
.picker image {
  width: 20px;
  height: 20px;
}
</style>
UniApp 下拉框组件示例代码 - 完整教程和示例

原文地址: https://www.cveoy.top/t/topic/lU3z 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录