Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

picker-view 设置value问题 #1162

Closed
freedom2012 opened this issue Dec 23, 2019 · 1 comment
Closed

picker-view 设置value问题 #1162

freedom2012 opened this issue Dec 23, 2019 · 1 comment

Comments

@freedom2012
Copy link

freedom2012 commented Dec 23, 2019

问题描述
js代码设置picker-view的value值,如果value下标为0的值是0是触发不了界面改变的,反而大于0可以,在小程序运行没有问题,就H5运行有问题

复现步骤
添加了一个按钮修改日期,修改value的值为[0,2,2],没有效果,如果把value第一项设置为大于0就可以改变界面

image

<template>
    <view>
        <page-head :title="title"></page-head>
        <view class="uni-padding-wrap">
             <view class="uni-title">
                   日期:{{year}}年{{month}}月{{day}}日
             </view>
	</view>
        <picker-view v-if="visible" :indicator-style="indicatorStyle" :value="value" @change="bindChange">
            <picker-view-column>
                <view class="item" v-for="(item,index) in years" :key="index">{{item}}年</view>
            </picker-view-column>
            <picker-view-column>
                <view class="item" v-for="(item,index) in months" :key="index">{{item}}月</view>
            </picker-view-column>
            <picker-view-column>
                <view class="item" v-for="(item,index) in days" :key="index">{{item}}日</view>
            </picker-view-column>
        </picker-view>
	<button @tap="changeDate">修改日期</button>
    </view>
</template>

<script>
    export default {
        data () {
            const date = new Date()
            const years = []
            const year = date.getFullYear()
            const months = []
            const month = date.getMonth() + 1
            const days = []
            const day = date.getDate()

            for (let i = 1990; i <= date.getFullYear(); i++) {
                years.push(i)
            }

            for (let i = 1; i <= 12; i++) {
                months.push(i)
            }

            for (let i = 1; i <= 31; i++) {
                days.push(i)
            }
            return {
                title: 'picker-view',
                years,
                year,
                months,
                month,
                days,
                day,
                value: [9999, month - 1, day - 1],
				/**
				 * 解决动态设置indicator-style不生效的问题
				 */
                visible: true,
                indicatorStyle: `height: ${Math.round(uni.getSystemInfoSync().screenWidth/(750/100))}px;`
            }
        },
        methods: {
            bindChange (e) {
                const val = e.detail.value
                this.year = this.years[val[0]]
                this.month = this.months[val[1]]
                this.day = this.days[val[2]]
            },
	    changeDate(){
		 this.value=[0,2,2]//this.value=[3,2,2]
	    }
        }
    }
</script>

<style>	
    picker-view {
        width: 100%;
        height: 600upx;
        margin-top:20upx;
    }

    .item {
        line-height: 100upx;
        text-align: center;
    }
</style>

预期结果
改变value的值改变界面

系统信息:

  • 发行平台: H5
  • 操作系统 chrome
  • HBuilderX 2.4.6
@freedom2012
Copy link
Author

问题已解决,感谢大神

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant