mpvue picker-view选择后视图跳回初始值

dbf7pr2w  于 4个月前  发布在  其他
关注(0)|答案(3)|浏览(65)

picker-view中, 滚动选择后, 视图会跳回到初始值.

代码:

<template>
  <div class="container">

    <view>{{year}}-{{month}}-{{day}}</view>
    <picker-view indicator-style="height: 50px;" style="width: 100%; height: 300px;" :value="initValue"
                 @change="onChange">
      <picker-view-column>
        <view v-for="item in years" style="line-height: 50px">{{item}}</view>
      </picker-view-column>
      <picker-view-column>
        <view v-for="item in months" style="line-height: 50px">{{item}}</view>
      </picker-view-column>
      <picker-view-column>
        <view v-for="item in days" style="line-height: 50px">{{item}}</view>
      </picker-view-column>
    </picker-view>

  </div>
</template>

<script>
  export default {
    data() {
      return {
        years: [2010, 2011, 2012, 2013, 2014, 2015],
        year: 2015,
        months: [1,2,3,4,5,6,7,8,9,10,11,12],
        month: 2,
        days: [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30],
        day: 2,
        initValue: [1,1,1]
      }
    },
    methods: {
      onChange: function(e) {
        const arr = e.mp.detail.value;
        this.year = this.years[arr[0]]
        this.month = this.months[arr[1]]
        this.day = this.days[arr[2]]
      },
    }
  };
</script>

测试中发现, 如果change事件函数体中为空则不会出现这个问题

z6psavjg

z6psavjg2#

issue超过30天无更新或响应,7天后将自动关闭,如果问题状态有更新请及时更新issue

相关问题