欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 新闻 > 国际 > vue3 发送 axios 请求时没有接受到响应数据

vue3 发送 axios 请求时没有接受到响应数据

2025/6/26 18:01:10 来源:https://blog.csdn.net/m0_75138009/article/details/144031114  浏览:    关键词:vue3 发送 axios 请求时没有接受到响应数据
<script setup>
import Edit from './components/Edit.vue'
import axios from 'axios'
import { onMounted,ref } from 'vue'// TODO: 列表渲染
//装数据的列表
const list = ref([])
const count = ref(0)
const getList = async () => {//通过发送 /list 请求从后端拿到列表数据const res = axios.get('/list')list.value = res.datacount.value++
}
onMounted(() => getList)
</script>

一开始一直怀疑是后端接口的问题,或者是前端请求路径的问题

最后排查了半天,通过 count 自增发现 getList 函数根本没有调用

检查 onMounted() 函数发现 是因为 getList 没有加括号 ()

正确写法:

<script setup>
import Edit from './components/Edit.vue'
import axios from 'axios'
import { onMounted,ref } from 'vue'// TODO: 列表渲染
//装数据的列表
const list = ref([])
const count = ref(0)
const getList = async () => {//通过发送 /list 请求从后端拿到列表数据const res = axios.get('/list')list.value = res.datacount.value++
}
onMounted(() => getList())
</script>

修改后成功接收到请求的参数:

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词