search
HomeWeChat AppletMini Program DevelopmentMini program implements interactive template analysis with background data, making it easy to get started

I have been working on a small program recently. It is relatively easy to design the page when I get started for the first time. But when it comes to interacting with the backend, I almost collapse. After looking at the official API, I still don’t know how to do it. I asked the seniors in the company and they directly told me I have written a template for me, let’s take a look:

/引入代码
var call = require("../util/request.js")

Page({
  data: {
    pictureList: [],
  },

  onLoad: function () {
    var that = this;
    //调用封装的方法,为了方便我直接在页面加载的时候执行这个方法
    call.getData(url, this.shuffleSuc, this.fail);
    this.loadMsgData(that);
  },
  shuffleSuc: function (data) {
    var that = this;
    that.setData({
      pictureList: data.rows
    })
    //我后面测试了一下,直接this.setData也可以,但是因为我在没有使用封装方法的时候
    //this.setData报过错,不能直接用this,所以我在赋值的时候一般都会加上var that = this;
  },
  fail: function () {
    console.log("失败")
  },
})

The front-end and back-end interaction is like this:

1. Under the condition that there is no need to pass a value: the background method uses GET

Mini program implements interactive template analysis with background data, making it easy to get started

This place needs to be changed to get, and then it can be written according to the template above

2. Some values ​​need to be passed: use POST in the background

Mini program implements interactive template analysis with background data, making it easy to get started

Then, change the template

call.request('corresponding background method', {value to be passed}, this.success, this.fail) here You need to give getData as a request, and then write the value in it and pass it to the backend. At the same time, the backend must have corresponding accepted variables;

For example: Mini program implements interactive template analysis with background data, making it easy to get started

I want to put the theme and The type and content are passed to the background, and at the same time it is necessary to know who wrote it (using openid), then the corresponding call is: call.request('method', {openid: the openid to be worn, title: e.detail.value( Get the value of input), type: Same reason, content: Same reason}, this.success, this, fail), corresponding to the background, I use a separate variable to receive openid, and the others use an object to receive it, so this is achieved The applet passed the value to the background;

The interaction between the applet and the background was realized in this way. Oops, I finally finished receiving all the data.

Related articles:

WeChat applet wx.request realizes background data interaction function analysis

WeChat applet realizes interaction with background PHP

Related videos:

WeChat Mini Program Event Interaction-Qianfeng Education WeChat Mini Program Development Video Tutorial

The above is the detailed content of Mini program implements interactive template analysis with background data, making it easy to get started. For more information, please follow other related articles on the PHP Chinese website!

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.