mirror of
https://github.com/zclzone/vue-naive-admin.git
synced 2025-12-28 20:10:22 +08:00
refactor: refactor api usage
This commit is contained in:
13
src/views/examples/table/post/api.js
Normal file
13
src/views/examples/table/post/api.js
Normal file
@@ -0,0 +1,13 @@
|
||||
import request from '@/utils/http'
|
||||
|
||||
export default {
|
||||
getPosts: (params = {}) => request.get('posts', params),
|
||||
getPostById: (id) => request.get(`/post/${id}`),
|
||||
savePost: (id, data = {}) => {
|
||||
if (id) {
|
||||
return request.put(`/post/${id}`, data)
|
||||
}
|
||||
return request.post('/post', data)
|
||||
},
|
||||
deletePost: (id) => request.delete(`/post/${id}`),
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import { h } from 'vue'
|
||||
import { NButton, NSwitch } from 'naive-ui'
|
||||
import { getPosts } from '@/api/post'
|
||||
import { formatDateTime } from '@/utils'
|
||||
import api from './api'
|
||||
|
||||
export const usePostTable = () => {
|
||||
// refs
|
||||
@@ -133,7 +133,7 @@ export const usePostTable = () => {
|
||||
|
||||
async function getTableData() {
|
||||
try {
|
||||
const res = await getPosts()
|
||||
const res = await api.getPosts()
|
||||
if (res.code === 0) {
|
||||
return res.data
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user