【发布时间】:2021-10-11 03:25:33
【问题描述】:
在我的模板中,我使用了以下代码:
<template>
{{ getScope(scope.row, itemIn.field) }}
</template>
在我使用的 Option API 中:
methods: {
getScope(data, key) {
const str_spl = key.split(".")
if(str_spl.length == 2) {
return data[str_spl[0]][str_spl[1]]
} else {
return data[key]
}
},
}
现在我想转向组合 API 方法。我创建了以下代码,但无法像使用 Options API 那样将其返回。如何解决?
setup() {
getScope(data, key) {
const str_spl = key.split(".")
if(str_spl.length == 2) {
return data[str_spl[0]][str_spl[1]]
} else {
return data[key]
}
}
return {
getScope,
};
}
【问题讨论】:
标签: vue.js vuejs3 vue-composition-api