daily-share
daily-share copied to clipboard
mobx轻量级状态管理(2020-2-13)
mobx轻量级
最简单的用法
import { observable, action } from 'mobx'
class UserStore {
@observable
public userInfo: any = {}
@observable
public shopInfo: any = {}
@observable
public staffInfo: any = {}
@observable
public token = ""
@action
public setUserInfo(userInfo: any) {
this.userInfo = userInfo
}
@action
public setShopInfo(shopInfo: any) {
this.shopInfo = shopInfo
}
@action
public setStaffInfo(staffInfo: any) {
this.staffInfo = staffInfo
}
@action
public setToken(token: string) {
this.token = token
}
public canIUse(id: number) {
if (this.staffInfo && this.staffInfo.permission_list) {
return this.staffInfo.permission_list.includes(id)
} else {
return false
}
}
}
export {
UserStore
}
export const userStore = new UserStore()
调用
import { userStore } from '@/store/modules/users'
//
userStore.setUserInfo('数据')