-- 创造无限可能

配送小程序:接口、页面跳转、获取数据

2023-07-07 00:04:21
290 人浏览 0 人点赞
有用,点赞支持一下

一、接口

1.引入:import http from ‘../../utils/http’;
2.创建订单列表:
return{
orderList: [], //订单列表
}
created() {
this.getOrderList()
},
3.获取订单列表:
methods: {
// 获取订单列表
getOrderList() {
http.get(‘/order/query’).then(res => {
this.orderList = res.data.lists
})
},
}

二、页面跳转

三、获取数据、保存数据

通过目录地址传送一个id

<navigator class="modify" :url="'/pages/shop/modify?id='+item.id" hover-class="navigator-hover">
修改
</navigator>
return里面定义一个id,id为空
return{
id:null
}
form:{
id:’’ // 默认为空
}
加载id:
onLoad(option) {
this.id = option.id
this.form.id = this.id
},
获取店铺数据
getShopInfo() {
http.get(‘/shop/info’, {
id: this.id
}).then(res => {
if (res.code == 0) {
this.form = res.data
}
})
},
创建店铺列表
createShop() {
http.post(‘/shop/save’, this.form).then(res => {
if (res.code == 0) {
alert(res.msg)
uni.switchTab({
url: ‘/pages/shop/select’
});
}
})
},

四、搜索

<u-search placeholder="日照香炉生紫烟" shape="round" v-model="keyword" @search='getOrderList'@custom='getOrderList' @clear='getOrderList'></u-search>
return里面添加keyword,默认为空
传入参数:
// 获取店铺列表
getShopList() {
http.get(‘/shop/query’, {
//传入参数
name: this.keyword
}).then(res => {
this.shopList = res.data.lists
})
}