vue3 reactive 請求接口數(shù)據(jù)賦值后拿不到的問題及解決方案
1、接口數(shù)據(jù)類型為:[{},{},{}]

// *** 方法一 ***
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()到此這篇關(guān)于vue3 reactive 請求接口數(shù)據(jù)賦值后拿不到的問題的文章就介紹到這了,更多相關(guān)vue3 reactive 賦值內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue+openlayers+nodejs+postgis實現(xiàn)軌跡運動效果
使用postgres(postgis)數(shù)據(jù)庫以及nodejs作為后臺,vue和openlayers做前端,openlayers使用http請求通過nodejs從postgres數(shù)據(jù)庫獲取數(shù)據(jù),這篇文章主要介紹了vue+openlayers+nodejs+postgis實現(xiàn)軌跡運動,需要的朋友可以參考下2024-05-05
Vue預(yù)覽PDF的兩種方法比較(vue-pdf-embed與pdfjs-dist)
這篇文章主要為大家詳細介紹了Vue預(yù)覽PDF的兩種方法比較,即vue-pdf-embed與pdfjs-dist,文中的示例代碼講解詳細,感興趣的小伙伴可以了解下2025-08-08
vuejs中監(jiān)聽窗口關(guān)閉和窗口刷新事件的方法
今天小編就為大家分享一篇vuejs中監(jiān)聽窗口關(guān)閉和窗口刷新事件的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-09-09
vue3+ts+elementui-plus二次封裝彈框?qū)崙?zhàn)教程
這篇文章主要介紹了vue3+ts+elementui-plus二次封裝彈框?qū)崙?zhàn)教程,本文通過實例代碼給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-07-07
vue項目中運用webpack動態(tài)配置打包多種環(huán)境域名的方法
本人分享一個vue項目里,根據(jù)命令行輸入不同的命令,打包出不同環(huán)境域名的方法。需要的朋友跟隨小編一起看看吧2019-06-06
windows下vue-cli導(dǎo)入bootstrap樣式
這篇文章主要介紹了windows下vue-cli導(dǎo)入bootstrap樣式,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-04-04

