Vue3 个人信息组件:使用 Axios 在 created 生命周期发起 POST 请求获取数据并渲染
<template>
<div>
<h1>个人信息</h1>
<p>账号:{{ account }}</p>
<p>名称:{{ name }}</p>
<p>等级:{{ level }}</p>
</div>
</template>
<script>
import axios from 'axios'
export default {
data() {
return {
account: '',
name: '',
level: ''
}
},
created() {
axios.post('/api/user/info')
.then(response => {
this.account = response.data.account
this.name = response.data.name
this.level = response.data.level
})
.catch(error => {
console.error(error)
})
}
}
</script>
原文地址: https://www.cveoy.top/t/topic/mmAb 著作权归作者所有。请勿转载和采集!