WeChat アプレットは自動的に一番下の実装計画までスクロールします
アプリケーションシナリオ: 例: チャット記録
wxml:
<scroll-view style="max-height: 100vh; background: pink;" scroll-y="true" scroll-into-view="{
{scrollLast}}">
<view wx:for="{
{dataList}}" id="lastPosition" style="border-bottom: 3rpx solid red; height: 100rpx;" id="item{
{index + 1}}">
{
{item}}
</view>
</scroll-view>
js:
Page({
/**
* 页面的初始数据
*/
data: {
scrollLast: null,
dataList: [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21]
},
getScollBottom() {
this.setData({
scrollLast: 'item' + this.data.dataList.length
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.getScollBottom();
},
})
効果:
ページを初めて入力すると、デフォルトでページが一番下までスクロールします。