Catalog: wechat cloud development technology can let us use part of the server for free and convenient functions, there is no need to build a background.
This tutorial is for beginners only, because I am a newcomer myself, and I welcome you to correct your mistakes.
The first step is to open cloud services;
Just click on Cloud Development in development tools and follow his steps
Step two: after opening, we can understand this page
Step 3: Initialize in app.js
Env: You can see your environment id in cloud development Settings. Just add in
OnLaunch () {wx.cloud.init({// initialize cloud development env:"" // This is your environment ID})}Copy the code
Step 4: Create the cloud function
Just configure it in the project.config.json file (as shown below)
Step 5: Create the cloud function file
In the cloud function, right-click new Node.js cloud function
Step 6: Enter this code in the index.js file of the Node.js file you created
Get () : fetch
Add () : adds
// cloud = require('wx-server-sdk') cloud.init() const db = cloud.database() // cloud = exports.main = Async (event, context) => {return await db.collection('cloud_text').get() // request}Copy the code
Step 6 (additional) : Sample step 6 real code
// cloud = require('wx-server-sdk') cloud.init() const db = cloud.database() // cloud = exports.main = async (event, Context) = > {let the author = event. The author | | '/ / keyword author let poem = event. The poem | |' / / poem let category = event. The category | | '/ / 0: poems; 1. primary school; 2. 3: high school let pages = event. Pages | | 0 / / page let pagesTotal = event. PagesTotal | | 10 / / access to pages if (poem! =''&&category! =''){ return await db.collection('miscellanies') .where({ category, poem:{ $regex:'.*' + poem, $options:'i' } }) .limit(pagesTotal) .skip(pages) .orderBy('time','asc') .get() }else if(poem! =''&& category==''){ return await db.collection('miscellanies') .where({ poem:{ $regex:'.*' + poem, $options:'i' } }) .limit(pagesTotal) .skip(pages) .orderBy('time','asc') .get() } else if(category! Collection ('miscellanies'). Where ({category}).limit(pagesTotal).skip(pages) .orderBy('time','asc') .get() }else if(author! Collection ('miscellanies'). Where ({author}).limit(pagesTotal).skip(pages). .orderby ('time','asc').get()}else {// Search for all return await db.collection('miscellanies').limit(pagesTotal).skip(pages) .orderBy('time','asc') .get() } }Copy the code
Step 7: If it is added, we can see the data in the cloud development, so you are basically getting started; Take a look at the documentation sometime
The last; I developed a small program of ancient poetry through cloud development, with search, copy, voice, preview and other functions, mainly including primary school, middle school, high school and other ancient poetry; Can draw lessons from a ha; Learn from each other. (search wX small program: ancient poetry book will) can