Skip to content

Commit 04305d6

Browse files
committedOct 15, 2020
ADD:$refs
1 parent 19613f3 commit 04305d6

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed
 

‎src/components/HelloWorld.vue

+10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<template>
22
<div class="hello">
33
<h1>{{ msg }}</h1>
4+
<input type="text" ref="inputRef" placeholder="ref focus">
45
</div>
56
</template>
67

@@ -9,8 +10,17 @@ import { Component, Prop, Vue } from 'vue-property-decorator';
910
1011
@Component
1112
export default class HelloWorld extends Vue {
13+
$refs!: {
14+
inputRef: HTMLInputElement;
15+
};
16+
1217
@Prop({ type: String }) msg!: string;
18+
19+
mounted() {
20+
this.$refs.inputRef.focus();
21+
}
1322
}
23+
1424
</script>
1525

1626
<!-- Add "scoped" attribute to limit CSS to this component only -->

‎src/pages/Jsx.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import { Vue, Component } from 'vue-property-decorator';
22
import { CreateElement } from 'vue';
33
@Component
44
export default class JSX extends Vue {
5-
count: number = 0;
6-
showInfo() {
5+
private count: number = 0;
6+
private showInfo() {
77
this.count++;
88
}
99

10-
render(h: CreateElement) {
10+
protected render(h: CreateElement) {
1111
return <h2 onMouseenter={this.showInfo}>JSX Test{this.count}</h2>;
1212
}
1313
}

0 commit comments

Comments
 (0)