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 赋值内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!

您可能感兴趣的文章: