实现 this 指向

This commit is contained in:
编码猿
2025-12-08 13:54:20 +08:00
parent dc70b5fc26
commit d1e37320d3
7 changed files with 280 additions and 70 deletions

View File

@@ -8,43 +8,44 @@ import { UserService, ResponseType } from "@service/user.service";
import { BaseLogic } from "@logic/base.logic";
import { Methods, VueCustomize } from "@logic/base.type";
export class HomeLogic<T extends VueCustomize> extends BaseLogic implements Methods {
export class HomeLogic<T extends VueCustomize> extends BaseLogic<T> implements Methods {
@Autowired()
public readonly UserService!: UserService;
public title: string = "12222";
public List: ResponseType[] = [];
// constructor() {
// super();
// }
public List: ResponseType[] = [
{ user_id: 1, user_name: '测试1' },
{ user_id: 2, user_name: '测试2' },
];
constructor(_: T) {
constructor() {
super();
console.log("constructor params: ", _);
this._ = _
}
/**
* 在这里面调用需要打开页面就执行的ajax请求
* @constructor
* 页面初始化调用的方法
*/
public async StartUp (): Promise<void> {
public async StartUp(): Promise<void> {
// 在StartUp方法中访问$route和$router
console.log("StartUp - this: ", this);
console.log("StartUp - this.$route: ", this.$route);
console.log("StartUp - this.$router: ", this.$router);
await this.getData();
}
/**
* 请求首页数据
*/
public async getData (): Promise<void> {
this.List = await this.UserService.UserList({ type: 1, page: 1 });
console.log("this.List: ", this.List);
public async getData(): Promise<void> {
// this.List = await this.UserService.UserList({ type: 1, page: 1 });
// console.log("this.List: ", this.List);
// let res = await this.UserService.login({ type: 2, page: 2 });
// console.log("this.res: ", res);
//
// await this._.$router.push('/About')
}