变量vm在哪里定义的?
Where is the variable vm defined?
我一直在浏览 JHipster 使用 clientFramework vue 生成的代码
entity-update.component.ts 文件每个都包含函数 beforeRouteEnter
,
在以下示例中,实体类型为 AppUser
我的问题是变量 vm
在哪里定义的?
我也没有在 main.ts 文件中看到 vm
的定义,该文件将 Vue 对象创建为:
main.ts
/* tslint:disable */
new Vue({
el: '#app',
components: { App },
template: '<App/>',
router,
provide: { ...
app-用户-update.component.ts
import { Component, Vue, Inject } from 'vue-property-decorator';
import { required } from 'vuelidate/lib/validators';
import AlertService from '@/shared/alert/alert.service';
import PersonService from '@/entities/iqcore/person/person.service';
import { IPerson } from '@/shared/model/iqcore/person.model';
import PartyService from '@/entities/iqcore/party/party.service';
import { IParty } from '@/shared/model/iqcore/party.model';
import { IAppUser, AppUser } from '@/shared/model/iqcore/app-user.model';
import AppUserService from './app-user.service';
const validations: any = {
appUser: {
userLogin: {
required,
},
},
};
@Component({
validations,
})
export default class AppUserUpdate extends Vue {
@Inject('appUserService') private appUserService: () => AppUserService;
@Inject('alertService') private alertService: () => AlertService;
public appUser: IAppUser = new AppUser();
@Inject('personService') private personService: () => PersonService;
public people: IPerson[] = [];
@Inject('partyService') private partyService: () => PartyService;
public parties: IParty[] = [];
public isSaving = false;
public currentLanguage = '';
beforeRouteEnter(to, from, next) {
next(vm => {
if (to.params.appUserId) {
vm.retrieveAppUser(to.params.appUserId);
}
vm.initRelationships();
});
}
created(): void {
this.currentLanguage = this.$store.getters.currentLanguage;
this.$store.watch(
() => this.$store.getters.currentLanguage,
() => {
this.currentLanguage = this.$store.getters.currentLanguage;
}
);
}
public save(): void {
this.isSaving = true;
if (this.appUser.id) {
this.appUserService()
.update(this.appUser)
.then(param => {
this.isSaving = false;
this.$router.go(-1);
const message = this.$t('iqcoreApp.iqcoreAppUser.updated', { param: param.id });
return this.$root.$bvToast.toast(message.toString(), {
toaster: 'b-toaster-top-center',
title: 'Info',
variant: 'info',
solid: true,
autoHideDelay: 5000,
});
})
.catch(error => {
this.isSaving = false;
this.alertService().showHttpError(this, error.response);
});
} else {
this.appUserService()
.create(this.appUser)
.then(param => {
this.isSaving = false;
this.$router.go(-1);
const message = this.$t('iqcoreApp.iqcoreAppUser.created', { param: param.id });
this.$root.$bvToast.toast(message.toString(), {
toaster: 'b-toaster-top-center',
title: 'Success',
variant: 'success',
solid: true,
autoHideDelay: 5000,
});
})
.catch(error => {
this.isSaving = false;
this.alertService().showHttpError(this, error.response);
});
}
}
public retrieveAppUser(appUserId): void {
this.appUserService()
.find(appUserId)
.then(res => {
this.appUser = res;
})
.catch(error => {
this.alertService().showHttpError(this, error.response);
});
}
public previousState(): void {
this.$router.go(-1);
}
public initRelationships(): void {
this.personService()
.retrieve()
.then(res => {
this.people = res.data;
});
this.partyService()
.retrieve()
.then(res => {
this.parties = res.data;
});
}
}
vm
是您的组件实例。它由路由器组件“注入”以访问例如应该呈现的组件内的函数。
有关详细信息,另请参阅 https://router.vuejs.org/guide/advanced/navigation-guards.html#in-component-guards。
我一直在浏览 JHipster 使用 clientFramework vue 生成的代码
entity-update.component.ts 文件每个都包含函数 beforeRouteEnter
,
在以下示例中,实体类型为 AppUser
我的问题是变量 vm
在哪里定义的?
我也没有在 main.ts 文件中看到 vm
的定义,该文件将 Vue 对象创建为:
main.ts
/* tslint:disable */
new Vue({
el: '#app',
components: { App },
template: '<App/>',
router,
provide: { ...
app-用户-update.component.ts
import { Component, Vue, Inject } from 'vue-property-decorator';
import { required } from 'vuelidate/lib/validators';
import AlertService from '@/shared/alert/alert.service';
import PersonService from '@/entities/iqcore/person/person.service';
import { IPerson } from '@/shared/model/iqcore/person.model';
import PartyService from '@/entities/iqcore/party/party.service';
import { IParty } from '@/shared/model/iqcore/party.model';
import { IAppUser, AppUser } from '@/shared/model/iqcore/app-user.model';
import AppUserService from './app-user.service';
const validations: any = {
appUser: {
userLogin: {
required,
},
},
};
@Component({
validations,
})
export default class AppUserUpdate extends Vue {
@Inject('appUserService') private appUserService: () => AppUserService;
@Inject('alertService') private alertService: () => AlertService;
public appUser: IAppUser = new AppUser();
@Inject('personService') private personService: () => PersonService;
public people: IPerson[] = [];
@Inject('partyService') private partyService: () => PartyService;
public parties: IParty[] = [];
public isSaving = false;
public currentLanguage = '';
beforeRouteEnter(to, from, next) {
next(vm => {
if (to.params.appUserId) {
vm.retrieveAppUser(to.params.appUserId);
}
vm.initRelationships();
});
}
created(): void {
this.currentLanguage = this.$store.getters.currentLanguage;
this.$store.watch(
() => this.$store.getters.currentLanguage,
() => {
this.currentLanguage = this.$store.getters.currentLanguage;
}
);
}
public save(): void {
this.isSaving = true;
if (this.appUser.id) {
this.appUserService()
.update(this.appUser)
.then(param => {
this.isSaving = false;
this.$router.go(-1);
const message = this.$t('iqcoreApp.iqcoreAppUser.updated', { param: param.id });
return this.$root.$bvToast.toast(message.toString(), {
toaster: 'b-toaster-top-center',
title: 'Info',
variant: 'info',
solid: true,
autoHideDelay: 5000,
});
})
.catch(error => {
this.isSaving = false;
this.alertService().showHttpError(this, error.response);
});
} else {
this.appUserService()
.create(this.appUser)
.then(param => {
this.isSaving = false;
this.$router.go(-1);
const message = this.$t('iqcoreApp.iqcoreAppUser.created', { param: param.id });
this.$root.$bvToast.toast(message.toString(), {
toaster: 'b-toaster-top-center',
title: 'Success',
variant: 'success',
solid: true,
autoHideDelay: 5000,
});
})
.catch(error => {
this.isSaving = false;
this.alertService().showHttpError(this, error.response);
});
}
}
public retrieveAppUser(appUserId): void {
this.appUserService()
.find(appUserId)
.then(res => {
this.appUser = res;
})
.catch(error => {
this.alertService().showHttpError(this, error.response);
});
}
public previousState(): void {
this.$router.go(-1);
}
public initRelationships(): void {
this.personService()
.retrieve()
.then(res => {
this.people = res.data;
});
this.partyService()
.retrieve()
.then(res => {
this.parties = res.data;
});
}
}
vm
是您的组件实例。它由路由器组件“注入”以访问例如应该呈现的组件内的函数。
有关详细信息,另请参阅 https://router.vuejs.org/guide/advanced/navigation-guards.html#in-component-guards。