我在查阅官方文档的时候,组件的写法是
// 定义一个名为 button-counter 的新组件
Vue.component('button-counter', {
data: function () {
return { count: 0 }
},
template: '<button v-on:click="count++">You clicked me {{ count }} times.</button>'
})
然后使用vue-property-decorator之后可以这么写:
新写一个buttonCounter.vue
buttonCounter.vue:
<button v-on:click="count++">You clicked me {{ count }} times.</button>
<script lang="ts">
import ... from .....
@component({componens:{...}})
export default class buttonCounter extends Vue{
public count = 0;
}
</script>
然后到想要使用它的地方import ... from ...
就可以了
当我看到异步组件的时候
Vue.component('async-example', function (resolve, reject) { setTimeout(function () {
// 向 \`resolve\` 回调传递组件定义
resolve({ template: '<div>I am async!</div>' })
}, 1000) })
我不知道该如何写成第二个代码块一样了