想要給Vue組件內(nèi)的某方法增加Decorator,發(fā)現(xiàn)并不能很好支持。importHellofrom'./components/Hello'importVuefrom'vue'importComponentfrom'vue-class-component'constlog=(target,name,descriptor)=>{constmethod=descriptor.valuedescriptor.value=(...args)=>{console.log(target,descriptor)method.apply(target,args)}returndescriptor}@Component({components:{Hello}})classAppextendsVue{str='Hello'@logfoo(){console.log(this.str)}}console.info('App',App)exportdefaultApp#app{font-family:'Avenir',Helvetica,Arial,sans-serif;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;text-align:center;color:#2c3e50;margin-top:60px;}foo添加裝飾器log之后,this不能正確的指向Component本身。。
Vue組件內(nèi)的方法如何添加裝飾器Decorator
慕標(biāo)琳琳
2019-05-25 13:31:25