以下是我目前的实现方式,无法解决这个问题
我想以 this.$const.color.red 获取CommonConst 类中的red常量和以
this.$const.routerName.login的方式获取RouterName 类中的login;
但因为typescript是单继承,所以我只能让Constants 类继承一个CommonConst ,不能将CommonConst和RouterName 一起继承
同时希望以面向对象的方式实现,编辑器可以通过类型提示出来 我输 this.$const.routerName.的时候就能提示出来routerName类中的所有属性
export default class RouterName {
public static login: string = 'login'
public static authentication: string = 'authentication'
public static search: string = 'search'
public static home: string = 'home'
public static talkList: string = 'talkList'
public static voice: string = 'voice'
public static voiceList: string = 'voiceList'
public static chat: string = 'chat'
public static message: string = 'message'
public static userDetail: string = 'userDetail'
public static match: string = 'match'
public static talkDetail: string = 'talkDetail'
public static notify: string = 'notify'
public static mine: string = 'mine'
public static talkAdd: string = 'talkAdd'
}
export default class CommonConst {
public static colorObj: Object = {
1: 'red',
2: 'pink',
3: 'purple',
4: 'blue',
5: 'teal',
6: 'green',
7: 'indigo',
8: 'orange',
9: 'brown',
}
}
export default class Constants extends CommonConst {
public static readonly sexList: Array<EnumVO> = [new EnumVO(1, '男'), new EnumVO(2, '女')]
public static readonly simpleDate: string = 'YYYY-MM-DD'
public static readonly regNotNum: RegExp = reg.regNotNum
public static readonly routerName: any = RouterName
}
import Constants from './constants'
export default (Vue) => {
Vue.prototype.$const = Constants
}