话不多说直接上代码
<template>
<view>
<view style="width: 300upx;height: 30px;" @click="change">改变</view>
<view style="width: 300upx;height: 30px;" @click="add">增加</view>
<scroll-view :style="'height:400px;width: 100%;position: absolute;'" scroll-y="true" :scroll-into-view="block" scroll-with-animation="true">
<view class="centermargin" v-for="(item,index) in array">
<view style="height: 100px;width: 100%;background-color: black;margin-top: 10upx" :id="'block'+index"></view>
</view>
</scroll-view>
</view>
</template>
以上是html,下面是js
<script>
export default {
data(){
return{
block:'',
num:5,
array:[1,1,1,1,1,1]
}
},
methods:{
change(){
this.block = 'block5'
},
add(){
this.array.push(1)
}
},
watch:{
'array':function (newval,oldval) {
this.block = 'block' + (newval.length-1)
}
},
onLoad(){
}
}
</script>
当watch中de this.block变成‘block’+(newval.length-1)时无效!当watch中de this.block变成‘block’+(newval.length-2)时有效!(就是说滚动到倒数第二个有效,但倒数第一个无效!)
7***@qq.com (作者)
点击增加时,watch里出现bug,-1可以滚动,-2无法滚动
2020-04-13 18:05