json 这么麻烦

This commit is contained in:
2025-11-06 20:59:18 +08:00
parent a0503d575e
commit aa3431856b
6 changed files with 354 additions and 26 deletions
+24
View File
@@ -1,4 +1,28 @@
import axios from 'axios'
import { myfuncs } from './myfunc'
export const my_network_func = {
post_json(path: string) {
const head_path = '/api/v1'
const url = head_path + path
const cookie = myfuncs.load('cookie') || ''
const data = {
cookie: cookie,
}
axios
.post(url, data, {
headers: {
'Content-Type': 'application/json',
},
})
.then((response) => {
console.log(response)
})
.catch((error) => {
console.error('There was an error!', error)
})
},
}
+37 -18
View File
@@ -1,26 +1,45 @@
<script setup lang="ts">
import MyOffcanvas from '@/components/MyOffcanvas.vue';
import { onMounted, ref } from 'vue';
const mos = ref<InstanceType<typeof MyOffcanvas> | null>(null);
import MyOffcanvas from '@/components/MyOffcanvas.vue'
import { onMounted, ref } from 'vue'
import { my_network_func } from '@/my_network_func'
const mos = ref<InstanceType<typeof MyOffcanvas> | null>(null)
onMounted(() => {
// 可以在这里调用mos.value的方法
//console.log('HomeView mounted', mos);
document.title = 'Operations.';
});
onMounted(() => {
// 可以在这里调用mos.value的方法
//console.log('HomeView mounted', mos);
document.title = 'Operations.'
})
function c(){
mos.value?.showAlert("success","111",1000);
}
function c() {
mos.value?.showAlert('success', '111', 1000)
}
export interface User {
id: number
name: string
}
function d() {
const jsonData = ref<User[]>([])
jsonData.value = [
{ id: 1, name: 'Alice'}
]
const Users: User= { id: 0, name: '' }
Users.id = 2
Users.name = 'Bob'
console.log('Users:', Users)
my_network_func.post_json('/1')
}
</script>
<template>
<div>
<MyOffcanvas ref="mos"/>
<button @click="c">ttt</button>
111
</div>
<div>
<MyOffcanvas ref="mos" />
<button @click="c">test1</button>
<button @click="d">test2</button>
</div>
</template>