
- 发布:2023-03-20 08:49
- 更新:2025-01-17 17:17
- 阅读:239
产品分类: uniapp/App
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: Windows 10 19044.1766
HBuilderX类型: 正式
HBuilderX版本号: 3.7.3
手机系统: 全部
手机厂商: 华为
页面类型: vue
vue版本: vue3
打包方式: 云端
项目创建方式: HBuilderX
测试过的手机:
示例代码:
<template>
<view>
<picker-view :value="solarValue" indicator-class="choose" @change="solarChange">
<picker-view-column>
<view class="item" v-for="(item,index) in solarInfo.years" :key="index">{{item}}年
</view>
</picker-view-column>
</picker-view>
</view>
</template>
<script setup>
import { reactive, computed, onMounted } from 'vue'
const solarInfo = reactive({
years: [],
yIdx: 0
})
const solarValue = computed(() => {
return [solarInfo.yIdx]
})
const solarChange = val => {
console.log("000000000000000000000000")
let {value} = val.detail
console.log(value)
console.log(solarValue.value)
}
onMounted(()=>{
solarInfo.years = Array(200).fill(0).map((item, idx) => 1900 + idx)
solarInfo.yIdx = solarInfo.years.indexOf(new Date().getFullYear())
})
</script>
<style scoped lang="scss">
picker-view {
width: 100%;
height: 300rpx;
margin-top: 20rpx;
}
::v-deep .choose {
height: 70rpx;
}
.item {
line-height: 70rpx;
text-align: center;
}
</style>
<template>
<view>
<picker-view :value="solarValue" indicator-class="choose" @change="solarChange">
<picker-view-column>
<view class="item" v-for="(item,index) in solarInfo.years" :key="index">{{item}}年
</view>
</picker-view-column>
</picker-view>
</view>
</template>
<script setup>
import { reactive, computed, onMounted } from 'vue'
const solarInfo = reactive({
years: [],
yIdx: 0
})
const solarValue = computed(() => {
return [solarInfo.yIdx]
})
const solarChange = val => {
console.log("000000000000000000000000")
let {value} = val.detail
console.log(value)
console.log(solarValue.value)
}
onMounted(()=>{
solarInfo.years = Array(200).fill(0).map((item, idx) => 1900 + idx)
solarInfo.yIdx = solarInfo.years.indexOf(new Date().getFullYear())
})
</script>
<style scoped lang="scss">
picker-view {
width: 100%;
height: 300rpx;
margin-top: 20rpx;
}
::v-deep .choose {
height: 70rpx;
}
.item {
line-height: 70rpx;
text-align: center;
}
</style>
操作步骤:
此代码初始化时候solarChange会被调用一次,app端返回错误下标,h5无异常
此代码初始化时候solarChange会被调用一次,app端返回错误下标,h5无异常
预期结果:
初始化时候solarChange不应该被调用
初始化时候solarChange不应该被调用
实际结果:
初始化时候solarChange被调用且返回下标错误
初始化时候solarChange被调用且返回下标错误
2 个回复
8***@qq.com - 没什么说的
您好,请问解决了吗
2***@qq.com
这里初始值不能设置 [0,0] 在app端,会触发change异常定位到[1,1]