鍍金池/ 問(wèn)答/HTML/ vue state在method中使用報(bào)undefined

vue state在method中使用報(bào)undefined

vuex中用mapstate映射state(代碼里面用的是attributeData: state => state.kickoff.attributeData),在模板<template v-for="(attritem, index) in attributeData">使用state可以訪問(wèn)到state的數(shù)據(jù),但是在method里面用this.attributeData并打印,都是undefined。想問(wèn)下怎么取不到attributeData值

回答
編輯回答
傲寒

template獲取數(shù)據(jù),method里面獲取數(shù)據(jù)機(jī)制不一樣的,用computed屬性做下轉(zhuǎn)化:

computed:{
    attrData(){
        return state.kickoff.attributeData
    }
}
2018年4月19日 16:16