Skip to content

Instantly share code, notes, and snippets.

@shd101wyy
Last active August 16, 2017 22:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shd101wyy/1cf8d57647ad575ad6ec14dd7ff1626f to your computer and use it in GitHub Desktop.
Save shd101wyy/1cf8d57647ad575ad6ec14dd7ff1626f to your computer and use it in GitHub Desktop.
Vue template
import Vue from "vue"
import Component from 'vue-class-component'
@Component({
template: `<div>
This is test {{message}}
<p v-for="l in list">
{{l}}
</p>
</div>`,
props: [
'message',
'list'
]
})
class TestComponent extends Vue {
}
// https://stackoverflow.com/questions/43703180/what-is-the-tag-name-of-class-based-vue-component
Vue.component('test', TestComponent) // <= register as global component
@Component({
template: `<div>
<p>Hi there! How have you been? {{name}}</p>
<button @click="onClick">Update</button>
<test message="hahahaha" :list="list"></test>
</div>`
})
class MyComponent extends Vue {
message: string = "Hi there"
name: string = "Yiyi"
list: string[] = ['a', 'b', 'c']
onClick() {
console.log('clicked')
this.name += '1'
this.list.push(Date.now()+'')
}
}
new Vue({
el: '#app',
render: h => h(MyComponent)
})
console.log('enter here 123')
{
"name": "vue_study",
"version": "0.0.1",
"description": "",
"main": "index.js",
"dependencies": {
"vue": "^2.4.2",
"vue-class-component": "^5.0.2"
},
"devDependencies": {
"@types/node": "^8.0.22",
"ts-loader": "^2.3.2",
"typescript": "^2.4.2",
"webpack": "^3.5.5"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
{
"include": [
"./src/**/*"
],
"compilerOptions": {
"outDir": "./out",
"allowSyntheticDefaultImports": true,
"lib": [
"dom",
"es5",
"es2015.promise"
],
"experimentalDecorators": true,
"module": "es2015",
"moduleResolution": "node",
"target": "es5",
"sourceMap": true,
"allowJs": true,
"watch": true
}
}
module.exports = {
devtool: 'inline-source-map',
entry: './src/app.ts',
output: {
filename: 'bundle.js'
},
resolve: {
// Add `.ts` and `.tsx` as a resolvable extension.
extensions: ['.ts', '.tsx', '.js'], // note if using webpack 1 you'd also need a '' in the array as well
alias: {
vue: 'vue/dist/vue.js'
}
},
module: {
loaders: [ // loaders will work with webpack 1 or 2; but will be renamed "rules" in future
// all files with a `.ts` or `.tsx` extension will be handled by `ts-loader`
{ test: /\.tsx?$/, loader: 'ts-loader' }
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment