微信小程序页面调用自定义组件内的事件
page
page.json
{ "usingComponents": { "my-component": "../components/component/component", } }
page.wxml
<my-component id="myComponent"></my-component>
page.js
Page({ //... onLoad: function () { let myComponent = this.selectComponent(‘#myComponent‘); // 页面获取自定义组件实例 myComponent.componentInnerFunction(); // 通过实例调用组件事件 } //... })
component
component.js
Component({ //... methods: { componentInnerFunction: function() { console.log(‘i am inner function‘); } } //... })