scroll-view解决切换置顶

This commit is contained in:
jqtmviyu@gmail.com 2021-02-25 15:27:30 +08:00
parent a8082b2761
commit 3a2ad8e278

View File

@ -12,7 +12,7 @@
<view @tap="onMenuTap(index)" :class="['menu_list', menuCurrent===index?'active':'']" v-for="(item,index) in menus" :key="item">{{item}}</view> <view @tap="onMenuTap(index)" :class="['menu_list', menuCurrent===index?'active':'']" v-for="(item,index) in menus" :key="item">{{item}}</view>
</view> </view>
<!-- 2.2 右列表: 电视,空调... --> <!-- 2.2 右列表: 电视,空调... -->
<view class="category_list"> <scroll-view class="category_list" scroll-y :scroll-top="scrollTop">
<view class="category_group" v-for="item in goods" :key="item.cat_name"> <view class="category_group" v-for="item in goods" :key="item.cat_name">
<!-- 2.2.1 标题 --> <!-- 2.2.1 标题 -->
<view class="category_group_title">{{item.cat_name}}</view> <view class="category_group_title">{{item.cat_name}}</view>
@ -24,7 +24,7 @@
</view> </view>
</view> </view>
</view> </view>
</view> </scroll-view>
</view> </view>
</view> </view>
</template> </template>
@ -41,6 +41,8 @@ export default {
menuCurrent: 0, menuCurrent: 0,
// //
goods: [], goods: [],
//
scrollTop: 0
} }
}, },
onLoad(){ onLoad(){
@ -60,10 +62,14 @@ export default {
this.goods = message[this.menuCurrent].children this.goods = message[this.menuCurrent].children
// console.log(this.goods); // console.log(this.goods);
}, },
//
onMenuTap(menuCurrent) { onMenuTap(menuCurrent) {
this.menuCurrent = menuCurrent this.menuCurrent = menuCurrent
this.goods = categoryData[menuCurrent].children this.goods = categoryData[menuCurrent].children
// 0,
this.scrollTop = Math.random() / 1000;
} }
} }
} }