点击菜单

1. 当前项高亮
2. 右侧切换到对应项
This commit is contained in:
jqtmviyu@gmail.com 2021-02-25 10:42:23 +08:00
parent ce53c58f68
commit 25610727b7

View File

@ -9,7 +9,7 @@
<view class="category_content"> <view class="category_content">
<!-- 2.1 左列表: 大家电,热门推荐,海外购... --> <!-- 2.1 左列表: 大家电,热门推荐,海外购... -->
<view class="menu"> <view class="menu">
<view class="menu_list" v-for="item in menu" :key="item">{{item}}</view> <view @tap="onMenuTap(index)" :class="['menu_list', menuCurrent===index?'active':'']" v-for="(item,index) in menus" :key="item">{{item}}{{index}}</view>
</view> </view>
<!-- 2.2 右列表: 电视,空调... --> <!-- 2.2 右列表: 电视,空调... -->
<view class="category_list"> <view class="category_list">
@ -30,16 +30,17 @@
</template> </template>
<script> <script>
// , , data,
let categoryData = {} let categoryData = {}
export default { export default {
data(){ data(){
return{ return{
// //
menu:[], menus:[],
// //
menuCurrent: 0, menuCurrent: 0,
// //
goods: [] goods: [],
} }
}, },
onLoad(){ onLoad(){
@ -49,13 +50,20 @@ export default {
// //
async getCategories(){ async getCategories(){
const { message } = await this.$u.api.getCategories() const { message } = await this.$u.api.getCategories()
//
categoryData = message categoryData = message
console.log(message); console.log(categoryData);
this.menu = message.map(v=>(v.cat_name)) //
console.log(this.menu) this.menus = message.map(v=>(v.cat_name))
// console.log(this.menu)
//
this.goods = message[this.menuCurrent].children this.goods = message[this.menuCurrent].children
console.log(this.goods); console.log(this.goods);
}, },
onMenuTap(menuCurrent) {
this.menuCurrent = menuCurrent
this.goods = categoryData[menuCurrent].children
}
} }
} }