在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
vue-property-decorator. @Prop!
Install: npm install --save vue-property-decorator
Child: <template> <div> {{fullMessage}} </div> </template> <script lang="ts"> import Vue from 'vue' import {Component, Prop} from 'vue-property-decorator' @Component({}) export default class Child extends Vue { message: string = "Hello"; @Prop({ type: String, default: 'Default Value' }) msg: string; get fullMessage() { return `${this.message},${this.msg}`; } } </script>
Parent: <template> <div class="hello"> <h1 v-colorDirective="{color: 'red', backgroundColor: 'blue'}">{{ message }}</h1> <button @click="clicked">Click</button> <ChildComp msg="'What a good day!'"/> <router-link to="/hello-ts">Hello Ts</router-link> </div> </template> <script lang="ts"> import Vue from 'vue' import Component from 'vue-class-component' import colorDirective from '../color-directive'; import ChildComp from './Child.vue'; @Component({ directives: { colorDirective }, components: { ChildComp } }) export default class Hello extends Vue { message: string = 'Welcome to Your Vue.js App' get fullMessage() { return `${this.message} from Typescript` } created() { console.log('created'); } beforeRouteEnter(to, from, next) { console.log("Hello: beforeRouteEnter") next() } beforeRouteLeave(to, from, next) { console.log("Hello: beforeRouteLeave") next() } clicked() { console.log('clicked'); } } </script>
|
请发表评论