D:\Code\asp-vue-new\long.client\src\views\order\index.vue
<script setup lang="ts">
import { useOrder } from "@/stores/order"
const storeOrder = useOrder();
onMounted(async () => {
// await storeOrder.setOrders();
// 👇
await storeOrder.setOrdersByMock();
})
</script>
<template>
<div></div>
</template>
<style lang="css"></style>
src\stores\order.ts
import { useOrderApi } from '@/api/order'
import { defineStore } from 'pinia'
export const useOrder = defineStore('orderStore', {
state: (): TOrderStoreState => ({
orders: []
}),
actions: {
getOrderById(id: number) {
},
getPickingTotalQuantityByOrderIdIdAndZdjhm(id: number, zdjhm: string) {
},
async setOrders() {
const res = await useOrderApi().getOrders()
this.orders = res.data
},
// 👇
async setOrdersByMock() {
const res = await useOrderApi().mockOrders()
this.orders = res.data
}
}
})
src\api\order\index.ts
import request from '@/utils/request'
import mockOrderData from './mock'
export function useOrderApi() {
return {
getOrders: (params?: object) => {
return request({
url: '/api/Orders/allOrder',
method: 'get',
params
})
},
// 👇
mockOrders: (params?: object) => {
// 👇
return mockOrderData()
}
}
}
src\api\order\mock.ts
// 👇
export const mockOrderData = () => ({
data: [
{
Id: 2,
CreatorId: 0,
CreationTime: '2024-07-18 10:39:49',
LastModificationTime: '0001-01-01 00:00:00'
}
]
})
export default mockOrderData