天天看點

vue getter 内部如何調用其它 getter

vue getter 内部如何調用其它 getter

今天遇到一個很白癡的問題,getter 如何調用其它 getter

問題

如下,我需要在 ​

​DevicePathNameMap​

​​ 中調用同級的另一個 ​

​getter: detailShowingPathArray​

​​,我以為隻需要 ​

​this.​

​ 即可,但是這樣找不到

getters: {
    // 比對數字名字 dataName 對應的裝置名字 title
    DevicePathNameMap: state => {
        let map = new Map()
        this.getter.detailShowingPathArray.forEach(item => {
        })
        return map
    },
    // nav-left 使用的路徑數組
    detailShowingPathArray: state => {
        let tempRouterPath = []
        // 中間其它代碼
        return tempRouterPath
    },
}      

正解

其實,隻需要在 getter 的參數中添加 getter 即可,可以傳遞多個 store 的參數: ​

​state​

​​ ​

​getter​

getters: {
    // 比對數字名字 dataName 對應的裝置名字 title
    DevicePathNameMap: (state, getter) => {
        let map = new Map()
        getter.detailShowingPathArray.forEach(item => {
        })
        return map
    },
    // nav-left 使用的路徑數組
    detailShowingPathArray: state => {
        let tempRouterPath = []
        // 中間其它代碼
        return tempRouterPath
    },
}      

繼續閱讀