vue3 reactive 请求接口数据赋值后拿不到的问题及解决方案
作者:RosyClouds~
这篇文章主要介绍了vue3 reactive 请求接口数据赋值后拿不到的问题及解决方案,本文通过实例代码给大家介绍的非常详细,需要的朋友可以参考下
1、接口数据类型为:[{},{},{}]

// *** 方法一 ***
let list: any = reactive([])
async function getData() {
const res = await tabsApi({ type: 1 })
console.log(res.data) // [{},{},{}]
list.push(...res.data)
}
getData()// *** 方法二 ***
let list: any = reactive({
listData:[]
})
async function getData() {
const res = await tabsApi({ type: 1 })
console.log(res.data) // [{},{},{}]
list.listData = res.data
}
getData()2、接口类型为:{title:‘lll’,bgList:‘www’}

// *** 方法一 ***
let totle = reactive({
titles:{}
})
async function getData() {
const res = await dashboardApi()
totle.titles = res.data.titles
}
getData()// *** 方法二 ***
let totle = reactive({})
async function getData() {
const res = await dashboardApi()
totle = Object.assign({},res.data.titles)
}
getData()到此这篇关于vue3 reactive 请求接口数据赋值后拿不到的问题的文章就介绍到这了,更多相关vue3 reactive 赋值内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
