博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[Vue + TS] Create your own Decorators in Vue with TypeScript
阅读量:4520 次
发布时间:2019-06-08

本文共 802 字,大约阅读时间需要 2 分钟。

We’ve used @Watch, @Inject and more decorators from . In this lesson however we will guide you through creating your own decorators in order to add common functionality to your Vue components using TypeScript.

 

Import:

import {createDecorator} from 'vue-class-component'

 

Define a decorator:

const Log = (msg) => {  return createDecorator((component, key) => {    console.log("#Component", component);    console.log("#Key", key); //log    console.log("#Msg", msg); //App  })}

 

Using it:

@Log('fullMessage get called')  get fullMessage() {    return `${
this.message} from Typescript` }

 

Output:

#Component Object {directives: Object, components: Object, name: "Hello", methods: Object, computed: Object…}#Key fullMessage#Msg fullMessage get called

 

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

你可能感兴趣的文章
爬虫入门【10】Pyspider框架简介及安装说明
查看>>
android面试(4)---文件存储
查看>>
(转载) 标准C中的字符串操作函数
查看>>
如何提高android串口kernel log等级
查看>>
Docker快速配置指南
查看>>
Python基础---OS模块 (二)
查看>>
【JS点滴】substring和substr以及slice和splice的用法和区别。
查看>>
awk多模式匹配
查看>>
线段树
查看>>
[javascript]实现登陆界面拖动窗口
查看>>
a span等行内元素加margin属性后无效果解决方案
查看>>
傻瓜式硬盘重装win7系统图文加视频教程
查看>>
BZOJ 1607 [Usaco2008 Dec]Patting Heads 轻拍牛头:统计 + 筛法【调和级数】
查看>>
如果一个人请优雅的活着。
查看>>
验证码
查看>>
Django缓存配置
查看>>
Ubuntu下安装 Mysql
查看>>
LeetCode--Reverse Integer
查看>>
PHP_APC+Ajax实现的监视进度条的文件上传
查看>>
计算机网络课堂笔记3.29
查看>>