Skip to content

chore(example): add child component #160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 12, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ import Component from 'vue-class-component'
}
})
export default class App extends Vue {
// props are had to declare again
propMessage: string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example in this readme is not written in typescript. So we should not include types.


// initial data
msg = 123

Expand All @@ -67,6 +70,12 @@ export default class App extends Vue {
// method
greet () {
alert('greeting: ' + this.msg)
this.$refs.helloComponent.sayHello()
}

// dynamic component
$refs: {
helloComponent: Hello
}
}
</script>
Expand Down
12 changes: 12 additions & 0 deletions example/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,25 @@
<p>helloMsg: {{helloMsg}}</p>
<p>computed msg: {{computedMsg}}</p>
<button @click="greet">Greet</button>
<hello ref="helloComponent">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing closing tag 👀

</div>
</template>

<script lang="ts">
import Vue from 'vue'
import Component from '../lib/index'
import Hello from './Hello.vue';

@Component({
props: {
propMessage: String
},
components: {
Hello
}
})
export default class App extends Vue {
// props are had to declare again
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

props had to be declared again ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about You have to declare props again. ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though the prop option in @Component is not a declaration, I think it is necessary to tell the starter why we have to declare propMessage again.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't it grammatically invalid that props are had to? I think we usually say props have to be in that case (sorry, my previous comment should be "have" instead of "had")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, my fault. 😆 I'll fix it now.
props have to be declared for typescript
Is it nicer or not ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it looks great 👍

propMessage: string

// inital data
Expand All @@ -40,6 +46,12 @@ export default class App extends Vue {
// method
greet () {
alert('greeting: ' + this.msg)
this.$refs.helloComponent.sayHello()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this causes compile error since all .vue files declared as Vue.
Did this example work in your machine?

Copy link
Contributor Author

@xingoxu xingoxu Oct 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ktsn helloComponent is decalred as Hello (see line 54)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I thought Hello should be also typed as typeof Vue because we has sfc.d.ts. But actually webpack resolves actual type. I didn't know that 😄

}

// dynamic component
$refs: {
helloComponent: Hello
}
}
</script>
19 changes: 19 additions & 0 deletions example/Hello.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<template>
<div class="hello">
<h1>Hello Times: {{ helloTimes }}</h1>
</div>
</template>

<script lang="ts">
import Vue from 'vue'
import Component from '../lib/index'

@Component
export default class Hello extends Vue {
helloTimes: number = 0
sayHello() {
this.helloTimes++;
}
}
</script>