Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ Note:

5. For all other options, pass them to the decorator function.

### Example

Following is the example written in Babel. If you are looking for TypeScript version, [it's in the example directory](example/example.ts).

``` js
import Vue from 'vue'
import Component from 'vue-class-component'
Expand Down
4 changes: 3 additions & 1 deletion example/example.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
<title></title>
</head>
<body>
<div id="el"></div>
<div id="el">
<app prop-message="World!"></app>
</div>
<script src="build.js"></script>
</body>
</html>
42 changes: 19 additions & 23 deletions example/example.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
import * as Vue from 'vue'
import Vue = require('vue')
import Component from '../lib/index'

@Component({
props: {
propMessage: String
}
},
template: `
<div>
<input v-model="msg">
<p>prop: {{propMessage}}</p>
<p>msg: {{msg}}</p>
<p>helloMsg: {{helloMsg}}</p>
<p>computed msg: {{computedMsg}}</p>
<button @click="greet">Greet</button>
</div>
`
})
class App extends Vue {
propMessage: string

// inital data
msg: number = 123

// use prop values for initial data
helloMsg: string = 'Hello, ' + this.propMessage

// lifecycle hook
Expand All @@ -25,30 +39,12 @@ class App extends Vue {
greet () {
alert('greeting: ' + this.msg)
}

render (h: Vue.CreateElement) {
return (
h('div', [
h('input', {
domProps: { value: this.msg },
on: {
input: (event: any) => {
this.msg = event.target.value
}
}
}),
h('p', ['prop: ', this.propMessage]),
h('p', ['msg: ', this.msg]),
h('p', ['helloMsg: ', this.helloMsg]),
h('p', ['computed msg: ', this.computedMsg]),
h('button', { on: { click: this.greet }}, ['Greet'])
])
)
}
}

// mount
new Vue({
el: '#el',
render: h => h(App, { props: { propMessage: 'World!' }})
components: {
App
}
})
7 changes: 6 additions & 1 deletion example/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ module.exports = {
path: './example',
filename: 'build.js'
},
resolve: {
alias: {
vue$: 'vue/dist/vue.common.js'
}
},
module: {
loaders: [
rules: [
{
test: /\.ts$/,
exclude: /node_modules|vue\/src/,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"rimraf": "^2.5.4",
"ts-loader": "^0.9.5",
"typescript": "^2.0.6",
"vue": "^2.0.3",
"vue": "^2.1.6",
"webpack": "^2.1.0-beta.27"
}
}