this ใซ้็ดใใ่จญ่จใจใใใฎใกใชใใใปใใกใชใใVue ใฏใฉในใณใณใใผใใณใใงใฏ
โ props, data, computed, methods, $store, $emitโฆ ใในใฆใ this ใซ้็ดใใใฆใใ
ใ ใใ this.name, this.count, this.increment() ใฎใใใซๅ
จ้จๅใๆธใๆนใงใขใฏใปในใงใใ
ๆฅฝใชๅ้ขใๅคง่ฆๆจกใซใชใใจใไฝใใฉใใใๆฅใใฎ๏ผใใใใใใซใใใชใ
โ ใๅฎๅ จใป่ฆใใใใใจใ่ฅๅคงๅใปใใกใใใกใใใฎไธก้ขใใใ่จญ่จ
this ใซ้็ดใใใใใฎใ@Component
export default class Example extends Vue {
@Prop() name!: string; // โ props โ this.name
count: number = 0; // โ data โ this.count
get upperName(): string { // โ computed โ this.upperName
return this.name.toUpperCase();
}
increment(): void { // โ methods โ this.increment()
this.count += 1;
}
}
| ๆฉ่ฝ | ๆธใๆน | ใฉใใขใฏใปในใใ๏ผ |
|---|---|---|
| props | @Prop() name!: string |
this.name |
| data | count: number = 0 |
this.count |
| computed | get upperName() { ... } |
this.upperName |
| methods | increment() { ... } |
this.increment() |
| Vue ๆฉ่ฝ | $store, $router, $emit |
this.$store.dispatch() ใชใฉ |
this ใซ้็ดใใ่จญ่จใฎใกใชใใใ| ใกใชใใ | ใชใ่ฏใ๏ผ |
|---|---|
| ใขใฏใปในใไธ่ฒซใใฆใใ | ใในใฆ this.xxx ใงใขใฏใปในใงใใ |
| ่จ่ฟฐใใทใณใใซ | ๆธใๆนใ่ฆใใใฎใ็ฐกๅ |
| ใฏใฉใน่จญ่จใซๆ ฃใใฆใใไบบใซใฏ้ฆดๆใฟใใใ | Java / C# ใชใฉใฎ OOP ๆๅใจ่ฟใ |
| TypeScript ใจใฎ้ฃๆบใๅฏ่ฝ | name!: string ใงๅไปใใงใใ |
this ใซ้็ดใใ่จญ่จใฎใใกใชใใใ| ใใกใชใใ | ใชใๅ้ก๏ผ |
|---|---|
| ไฝใใฉใใใๆฅใใฎใใใใใซใใ | this.name ใ props ใชใฎใ data ใชใฎใไธ่ฆใใใใชใ |
ๅคง่ฆๆจกใซใชใใจ this ใ่ฅๅคงๅใใ |
ไผผใๅๅใๅขใใฆ่ก็ชใใใใใ่ชญใฟใฅใใ |
| ใญใธใใฏใฎๅๅฉ็จใใใซใใ | this ใซไพๅญใใฆใใใจ composable ใซใงใใชใ |
this ใฎในใณใผใใ้้ใใใใ |
้ขๆฐใๆธกใๆใซ this ใใบใฌใฆใจใฉใผใซใชใ๏ผbind ๅฟ
่ฆ๏ผ |
this ใงใฉใใใๆฅใใใใใใซใใใณใผใใconsole.log(this.name); // โ props ใ data ใใใใใชใ
console.log(this.count); // โ ใใใ data ใชใฎใ computed ใชใฎใ๏ผ