[Vue @Component] Simplify Vue Components with vue-class-component

Vue-Class-Component实战
本文介绍如何使用vue-class-component简化Vue组件开发流程。通过在类中直接定义数据属性和方法,替代传统Vue组件的数据函数和方法对象。文章提供了一个简单的示例,展示了如何创建一个包含点击事件处理的组件。

While traditional Vue components require a data function which returns an object and a method object with your handlers, vue-class-componentflattens component development by allowing you to add your data properties and handlers directly as properties of your class.

 

Install:

npm install vue-class-component --save

 

jsconfig.json:

{
    "compilerOptions": {
        "experimentalDecorators": true
    }
}

 

 

App.vue:

<template>
  <h1 @click="onClick">
    {{message}}
  </h1>
</template>

<script>
import Vue from "vue"
import Component from "vue-class-component"

@Component({})
export default class App extends Vue {
  message = "Hello from class"

  onClick() {
    this.message = "Goodbye"
  }
}
</script>

 

转载于:https://www.cnblogs.com/Answer1215/p/9343597.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值