功能簡要描述:
頁面UI.png

頁面UI.png
分類頁面,左面是分類名稱列表,右邊是分類名稱+分類下商品
點(diǎn)擊分類名稱后,定位到商品列表的分類名稱位置
template代碼塊(簡化)
<!-- 分類名稱列表 -->
<view style='width:100vw;display:flex'>
<scroll-view style='height:100vh;width:20%' :scroll-y="true">
<view>
<view @click='intoDom(item.id)' v-for(item,index) in list :key='index'>分類名稱</view>
</view>
</scroll-view>
<!-- 商品列表 -->
<scroll-view style='height:100vh;width:80%' :scroll-y="true" :scroll-into-view="intoId">
<view>
<view v-for(item,index) in list :key='index'>
<view :id="'dom_'+item.id" >分類名稱</view>
<view v-for(subItem,subIndex) in item.subList :key='subIndex'>商品名稱</view>
</view>
...更多數(shù)據(jù)(略)
</view>
</scroll-view>
</view>
script代碼塊(出現(xiàn)BUG代碼)
export default {
data() {
return {
intoId: "",// 值應(yīng)為某子元素id(id不能以數(shù)字開頭)。設(shè)置哪個方向可滾動,則在哪個方向滾動到該元素
list: [{
typename: "分類1",
id: 1,
subList: [{
itemname: "商品1",
id: "1001"
}]
}]
}
},
methods: {
// 點(diǎn)擊左邊分類名稱,定位到商品分類塊位置
intoDom(id){
this.intoId = `dom_${id}`
}
}
}
修改后script代碼
export default {
data() {
return {
intoId: "",// 值應(yīng)為某子元素id(id不能以數(shù)字開頭)。設(shè)置哪個方向可滾動,則在哪個方向滾動到該元素
list: [{
typename: "分類1",
id: 1,
subList: [{
itemname: "商品1",
id: "1001"
}]
}]
}
},
methods: {
// 點(diǎn)擊左邊分類名稱,定位到商品分類塊位置
intoDom(id){
// 先設(shè)置一個錯誤的ID
this.intoId = `dom_${id}_xxx`
// 然后再設(shè)置正確的滾動ID
setTimeout(()=>{
this.intoId = `dom_${id}`
},100)
}
}
}