1.0.2 • Published 3 years ago

vue-function-trace v1.0.2

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

安装

npm i vue-function-trace --save

class中使用

import { logPerformance , FunctionTraceStash } from "vue-function-trace";

interface IPerson {
    userName: string;
    SexName: string;
}

class Person {
    userName: string;
    SexName: string;

    constructor(userName?: string, SexName?: string) {
        this.userName = userName;
        this.SexName = SexName;
    }

    @logPerformance
    setUserName(userName: string) {
        this.userName = userName;
    }

    @logPerformance
    setUserSexName(SexName: string) {
        this.SexName = SexName;
    }

    @logPerformance
    setPersonInfo(userName: string, SexName: string) {
        this.setUserName(userName)
        this.setUserSexName(userName)
    }

    @logPerformance
    getPersonInfo(): IPerson {
        let index = 0
        while (index < 100000){
            index++
        }
        return {
            userName: this.userName,
            SexName: this.SexName
        }
    }
}


let person = new Person("John", "男");
person.setPersonInfo("John-0", "男-0")
let personInfo = person.getPersonInfo()

// 打印堆栈信息
console.log(FunctionTraceStash.getInstance().printTraceList())

// 重放该堆栈
FunctionTraceStash.getInstance().replay()

// 清空堆栈
FunctionTraceStash.getInstance().clear()

vue单文件组件中使用

<template>
  ../
</template>

<script>
  import { logPerformance , FunctionTraceStash } from "vue-function-trace";

  export default {
    methods: {
      @logPerformance
      test(){}
    }
}
</script>