详见:码云小程序demo1页面点击左边侧边栏,右侧边栏刷新获取新的数据
1.前端:
wxml
:点击事件changeMenu
<view wx
:key
='i' bindtap
="changeMenu" data
-i
='{{index}}'
class="{{activeIndex===index?'active':''}}" wx
:for='{{menu}}'>{{item
.name
}}</view
>
js
:
changeMenu(e
) {
let {
i
} = this.$d(e
);
this.setData({
activeIndex
: i
})
this.getGoodsList()
},
onLoad
: function (options
) {
this.getTypeList()
},
async getTypeList() {
let {
list
} = await this.$
get('http://localhost:8989/typeList')
this.$
set('menu', list
)
this.getGoodsList()
},
async getGoodsList() {
let list
= await this.$
get('http://localhost:8989/goodsList', {
type
: this.data
.menu
[this.data
.activeIndex
].id
})
this.$
set('goodslist', list
)
console
.log(list
);
},
2.后台
详见:码云小程序demo1
let typeList
= mock
.mock({
'list|10': [
{
'id|+1': 1,
name
: "@cword(2,4)",
}
]
})
let goodsList
= mock
.mock({
'list|100': [
{
'id|+1': 1,
name
: "@cword(2,4)",
avatar
: "https://dss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=3181961039,740550858&fm=26&gp=0.jpg",
type
: "@natural(1,10)",
price
: "@natural(10,30)"
}
]
})
app
.get('/goodsList', (req
, res
) => {
let data
= goodsList
.list
.filter(r
=> r
.type
=== parseInt(req
.query
.type
))
res
.json(data
)
})
app
.get('/typeList', (req
, res
) => {
res
.json(typeList
)
})
转载请注明原文地址:https://tech.qufami.com/read-917.html