上一篇,我基本图解了详细过程,后续我就直接贴代码了。
'use strict';
exports.main = async (event, context) => {
let { categroyId } = event
//模拟查询数据库,获取数据
let arr = [
{"id":1,"title":'商品1',"categroyId":1,"price": 999.99},
{"id":2,"title":'商品2',"categroyId":1,"price": 999.99},
{"id":3,"title":'商品3',"categroyId":1,"price": 999.99},
{"id":4,"title":'商品4',"categroyId":1,"price": 999.99},
{"id":5,"title":'商品5',"categroyId":1,"price": 999.99}
]
return arr;
};
<template>
<view class="home">
<view class="row" v-for="item in dataList" :key="item.id">
<text class="txt">商品id:{{item.id}}</text>
<text class="txt">商品名称:{{item.title}}</text>
<text class="txt">商品价格:{{item.price}}</text>
</view>
</view>
</template>
<script>
export default {
data() {
return {
dataList:[]
}
},
onLoad() {
uniCloud.callFunction({
name:"myFunc1"
}).then(res=>{
console.log(res);
});
uniCloud.callFunction({
name:"myFunc2",
data:{
categoryId:1
}
}).then(res=>{
console.log(res);
this.dataList = res.result;
});
},
methods: {
}
}
</script>
<style>
.home{
.row{
padding: 30rpx;
border-bottom: 1px solid #ccc;
.txt{
padding: 0 20rpx;
}
}
}
</style>
结果图示