异步方法每次返回的字符串如何拼接成数组或者对象呢,
在工作的时候经常遇到, 一直不太会处理,
全部代码是从这里拷贝的,
vue中教你用decorator实现无痕埋点
export function Buried(target, funcName, descriptor) {
let oriMethods = Object.assign({},target.methods),
oriTarget = Object.assign({},target);
// methods方法中
if(target.methods) {
for(let name in target.methods) {
target.methods[name] = function () {
let result = oriMethods[name].call(this,...arguments);
// 如果方法中返回 noBuried 则不添加埋点
if(typeof result === 'string' && result.includes('noBuried')) {
console.log(name + '方法设置不添加埋点');
} else if(result instanceof Promise) {
result.then(res => {
if(typeof res === 'string' && res.includes('noBuried')) { console.log(name + '方法设置不添加埋点'); return; };
console.log('添加埋点在methods方法中:' , name.toUpperCase ());
this.$log(name);
});
}else{
console.log('添加埋点在methods方法中:' , name.toUpperCase ());
this.$log(name);
};
return result;
}
}
}
// 钩子函数中
const hookFun = (funName) => {
target[funName] = function() {
let result = oriTarget[funName].call(this,...arguments);
console.log('添加埋点,在钩子函数' + funName + '中:', 'VIEW');
this.$log('VIEW');
return result;
}
}
// 钩子函数中 view
if (target.activated) {
return hookFun('activated');
} else if (target.created) {
return hookFun('created');
} else if (target.mounted) {
return hookFun('mounted');
};
}
这样应用的:
import { Buried } from '@/libs/decorators';
@Buried
methods: {
...
}
入口文件设置:
Vue.prototype.$log = function leStatic (actiontype) {
console.log(actiontype)
}
返回的是:
getRegion main.js?3479:22
setService main.js?3479:22
setRegionDefalut main.js?3479:22
updateLogo main.js?3479:22
会看到每次返回的都是字符串,
能否把每次返回的字符串,
处理成数组或者对象呢,
求教,谢谢!
改成
console.log([actiontype])
或者emit的时候传过来数组?
或者接收到了整理一下?或者触发的时候整理一下?