系列:vue"/>
vue2 系列:vue
前言:vue2.0 支持 ts,需要用到 vue-property-decorator
1. 安装
npm i -D vue-property-decorator
2. 用法
// vue, compnent 必引入,其他按需引用
import { Vue, Component, Prop, PropSync, Watch, Emit } from "vue-property-decorator";
// 必须的
@Component();
export default class Demo extends Vue {// Prop, ! 表示非 null,非 undefined@Prop({ default: 18 })age!: number;// PropSync, 实现组件双向绑定,可以修改传过来的值@PropSync('sex', { type: String })syncedsex!: string;// dataname: string = 'yqcoder';// Watch@Watch('name', { immediate: true, deep: true })onChangeName(new, old) {}// computedget nameL() {return this.name.length}// Emit: this.$emit('reset-name', 'yq')@Emit()resetName() {return 'yq'}
}
更多推荐
vue2 系列:vue
发布评论