Vue商品控件与购物车联动效果的实例代码

2020-06-14 06:26:32易采站长站整理

selectMenu(index) {
let foodlist = this.$refs.foodScroll.getElementsByClassName(
"food-list-hook"
);
// 根据下标,滚动到相对应的元素
let el = foodlist[index];
// 滚动到对应元素的位置
this.foodScroll.scrollToElement(el, 100);
}
}
};
</script>

定义商品组件的样式


<style scoped>
.goods {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
position: absolute;
top: 190px;
bottom: 51px;
overflow: hidden;
width: 100%;
}
.goods .menu-wrapper {
-webkit-box-flex: 0;
-ms-flex: 0 0 85px;
flex: 0 0 85px;
background: #f4f4f4;
}
.goods .menu-wrapper .menu-item {
padding: 16px 23px 15px 10px;
border-bottom: 1px solid #e4e4e4;
position: relative;
}
.goods .menu-wrapper .menu-item.current {
background: white;
font-weight: bold;
margin-top: -1px;
}
.goods .menu-wrapper .menu-item:first-child.current {
margin-top: 1px;
}
.goods .menu-wrapper .menu-item .text {
font-size: 13px;
color: #333333;
line-height: 17px;
vertical-align: middle;
-webkit-line-clamp: 2;
display: -webkit-box;
-webkit-box-orient: vertical;

overflow: hidden;
}
.goods .menu-wrapper .menu-item .text .icon {
width: 15px;
height: 15px;
vertical-align: middle;
}
.goods .menu-wrapper .menu-item .num {
position: absolute;
right: 5px;
top: 5px;
width: 13px;
height: 13px;
border-radius: 50%;
color: white;
background: red;
text-align: center;
font-size: 7px;
line-height: 13px;
}

.goods .foods-wrapper {
-webkit-box-flex: 1;
-ms-flex: 1;
flex: 1;
/* background: blue; */
}
.goods .foods-wrapper .container-list {
padding: 11px 11px 0 11px;
border-bottom: 1px solid #e4e4e4;
}
.goods .foods-wrapper .container-list img {
width: 100%;
margin-bottom: 11px;
border-radius: 5px;
}
.goods .foods-wrapper .food-list {
padding: 11px;
}
.goods .foods-wrapper .food-list .title {
height: 13px;
font-size: 13px;
background: url(btn_yellow_highlighted@2x.png) no-repeat left center;
background-size: 2px 10px;
padding-left: 7px;
margin-bottom: 12px;
}

.goods .foods-wrapper .food-list .food-item {
display: flex;
margin-bottom: 25px;
position: relative;
}
.goods .foods-wrapper .food-list .food-item .icon {
flex: 0 0 63px;
background-position: center;
background-size: 120% 100%;
background-repeat: no-repeat;
margin-right: 11px;
height: 75px;
}
.goods .foods-wrapper .food-list .food-item .content {
flex: 1;
}
.goods .foods-wrapper .food-list .food-item .content .name {