# 前言
这里介绍如何在插件中对数据进行处理及通过API获取数据
# handler
# handler文件调用
<script>
import SDK from '@tencent/tapd-open-js-sdk'
export default {
...
async mounted() {
this.sdk = SDK();
const msg = await this.sdk.handler('hello.index')
const msg = await this.sdk.handler('hello.getStoriesCount', {
id: '755'
}))
}
...
};
</script>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# handler文件示例handler/hello.js
const { tapdSdk } = require('@tencent/tplugin-core');
exports.index = data => 'Hello World!';
exports.getStoriesCount = async (params) => {
// params
// {
// workspace_id: '20375640',
// data: { id: '755', app_code: 'HelloWorld', handler: 'hello.getStoriesCount' }
// }
const { data } = params
try {
const count = await tapdSdk.getStoriesCount({'workspace_id': data.id})
return count;
} catch {
// ...
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18