
我向通过面板上的一个按钮来响应脚本里面的某个方法,应该怎么写呢?

我向通过面板上的一个按钮来响应脚本里面的某个方法,应该怎么写呢?
这个问题我也研究了好久,没有找到特别好的办法。。
我是这样做的:
// ui-button是Creator的button组件,button是Chrome原生的button
Vue.component("ButtonExample", {
template: `
<ui-button @confirm="onClick">Button</ui-button>
<button @click="onClick">Button</button>
`,
props: {
target: {
twoWay: true,
type: Object,
}
},
methods: {
onClick() {
// 通过cc.find找到某个节点和上面的组件
cc.log(cc.find('Canvas'));
// 调用脚本注册的全局函数或变量
window.someMethod(window.someVariable);
}
}
});
多谢分享