不用与以往使用vue的情况,使用typescript + vue-property-decorator 的一些写法
原来使用 vue时
export default {
data() {
const statusDict = {
on: '开启',
off: '关闭'
} // 如何能在使用 vue-property-decorator的时候写这样的逻辑
return {
statusDict,
id: this.$route.params.id //如何能在定义时使用this.$route
}
}
}
目前使用 vue-property-decorator时
// 逻辑部分
@Component
export default class YourComponent extends Vue {
statusDict: string = { ... } // 有逻辑的部分只能放在外面,比较丑陋
id:number; // 初始化(比如用到了$route,没法直接写)我只能放到created生命周期里面去写,这样比较丑陋
}
不知道大家有没有更好的办法,可以优雅一些的处理这两个问题
你也可以写构造函数里啊
再说了,
created
是生命周期事件,该在这里写的就得在这里写,怎么能说丑陋……