axios.get()是axios发送get请求的方法
axios.post()是axios发送post请求的方法
<script setup>
import axios from 'axios'
import {ref,reactive} from 'vue'
//let message = ref('')
let message = reactive({
code:'',
content:''
})
function getLoveWords(){
//axios.get(url)
//axios.get(url,{请求的其他信息})
//axios.get(url,{params:{键值对参数}},header:{设置一些特殊的请求头})
//return axios.get('https://api.uomg.com/api/rand.qinghua?format=json')
// return axios.get(
// 'https://api.uomg.com/api/rand.qinghua',
// {
// params:{
// format:'json',
// username:'zhangsan',
// userPwd:'123456'
// },
// headers:{
// Accept:'application/json, text/plain, text/html,*/*'
// }
// }
// )
//axios.post(url)
//axios.post(url,{请求的其他信息})
//axios.post(url,{要放入请求体的JSON串},{params:{键值对参数}},header:{设置一些特殊的请求头})
//axios.post(url,{username:'zhangsan'},{params:{键值对参数}},header:{设置一些特殊的请求头})
//return axios.post('https://api.uomg.com/api/rand.qinghua?format=json')
return axios.post(
'https://api.uomg.com/api/rand.qinghua',
{
username:'zhangsan',
userPwd:'123456'
},
{
params:{
format:'json',
},
headers:{
Accept:'application/json, text/plain, text/html,*/*'
}
}
)
}
async function getLoveMessage(){
let {data} = await getLoveWords()
Object.assign(message,data)
}
</script>
<template>
<div>
<h1 v-text="message.content"></h1>
<button @click="getLoveMessage">变</button>
</div>
</template>
<style scoped>
</style>