如何以及在哪里把项目在localStorage的商店

问题描述 投票:0回答:1

我使用离子4和角度。也插件 - NG2 - 终极版。

我分派事件。我抓住它在商店。我把抓住项目在店里,但我还需要是把该项目中的localStorage。如你所知,我没有window.localStorage,因为我开发的应用程序离子。所以我需要包括存储模块,我也需要一个构造函数注入,但我没有在商店的构造函数。并且人也说不会写把项目中的localStorage在减速。所以我该怎么办?

import { SET_USER_ROLE } from "./actions";
import { Storage } from '@ionic/storage'
export interface IUsersState{
    access_token : string,
    refresh_token :string, 
    role_name: string,
    data: Object
}

export const USERS_INITIAL_STATE: IUsersState = {
    access_token: null,
    refresh_token: null,
    role_name: null,
    data : null
}

export function usersReducer(state: IUsersState = USERS_INITIAL_STATE, action) : IUsersState{
    switch(action.type){
        case SET_USER_ROLE =>{
            // I want to put role_name in localstorage but to do that, i have to write 
            // this.storage.set (but storage needs to be injected in constructor, but i don't have one)
            // also it's said that it's bad to put it in localstorage at this place reducer.
            return {...state, role_name: action.role_name};
        }
    }
    return state;
}
angular ionic-framework redux ionic2 ionic3
1个回答
0
投票

您可以使用intel security插件。

© www.soinside.com 2019 - 2024. All rights reserved.