How does Mini Program bind a click event to the view of the index page and execute the method in app.js?

I bound the same click event to the button tags of some child pages, such as getFormID, so I put getFormID in app.js. Sub-page button binding click event when the direct bindtap= "getFormID" can not be executed, prompting that there is no getFormID method in page, how can you bind to the getFormID in app.js?


Why should getFormID be bound to app.js? Are there too many the same events? I think we can put it in a package and put it in other js files


Mini Program doesn't have the native mixin function, but that doesn't mean we can't implement it ourselves. Considering the page initialization of Page (init) , you can do this:

  

the top of the index.js page needs const app = getApp () and then you can write app.getFormId () by referring to the method in app.js. It's not as complicated as those upstairs. Of course, it is not recommended that you put the common function of in app.js. You can customize a .js file in the utils folder and then introduce it in the pages you need

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b332b0-2be66.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b332b0-2be66.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?