Where is the WeChat applet calling interface written?

angryTom
Release: 2020-03-24 13:41:11
Original
9806 people have browsed it

Where is the WeChat applet calling interface written?

Where to write the WeChat applet calling interface

The WeChat applet calling interface can be written in the life cycle callback function of the applet, such as onLaunch, onShow, onHide, etc. can also be written in custom functions, such as custom button click events viewTap, etc.

Recommended learning:Small program development

Where is the WeChat applet calling interface written?

1. Write the calling interface code in the life cycle of App() In the callback function

App({ onLaunch (options) { // 调用接口,发送网络请求 wx.request({ url: 'test.php', //仅为示例,并非真实的接口地址 data: { x: '', y: '' }, header: { 'content-type': 'application/json' // 默认值 }, success (res) { console.log(res.data) }}) } )
Copy after login

2. Write the interface calling code in the custom function

//index.js Page({ // 自定义函数 viewTap: function() { // 调用接口,发送网络请求 wx.request({ url: 'test.php', //仅为示例,并非真实的接口地址 data: { txt: '123' }, header: { 'content-type': 'application/json' // 默认值 }, success (res) { console.log(res.data) }}) } })
Copy after login

PHP Chinese website, a large number oflaravel tutorials, welcome to learn!

The above is the detailed content of Where is the WeChat applet calling interface written?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!