While traditional Vue components require a data function which returns an object and a method object with your handlers, vue-class-component
flattens component development by allowing you to add your data properties and handlers directly as properties of your class.
Install:
npm i --save vue-class-component vue-property-decorator
jsonfing.json:
{ "compilerOptions": { "experimentalDecorators": true } }
HelloWorld.vue:
<template> <div @click="onClick" class="hello"> {{message}} </div> </template> <script> import {Component, Prop, Vue} from ‘vue-property-decorator‘ @Component({}) export default class HelloWorld extends Vue { @Prop({ default: ‘Default message from Hello World Component‘ }) message onClick() { this.message = ‘Goodbye‘ } } </script>
原文地址:https://www.cnblogs.com/Answer1215/p/9350904.html
时间: 2024-10-25 06:35:36