


Structural Overview of the Basics of WeChat Mini Program Development (2)
微信小程序开发教程(基础篇)1-初识微信小程序
在上一篇教程的最后,我们生成了一个类似"Hello World"的小程序,这个过程中没有编写任何一行代码。
在新建一个项目后,微信小程序会生成一个默认的程序框架,后续程序的开发工作都在这个框架上进行。这个默认框架包含下面几部分:
app.xx
每个微信小程序都会包含app.js, app.json, app.wxss 三个文件,其中app.js文件包含了程序的逻辑实现代码,app.json是一个全局配置文件,app.wxss是一个全局样式文件。后面会详细介绍每个文件的内容和作用。
pages 目录
pages目录包含了程序当前的页面文件,以默认生成的程序为例,该目录下包含了index,logs两个目录,说明程序包括index和logs两个页面。
以index为例,该目录下包含index.js,index.wxss,index.wxml3个文件,其中js是代码文件,wxss是样式文件,wxml是页面结构描述文件。
熟悉web开发的同学应该会感觉很熟悉。微信小程序的开发模式确实和web开发很相似。目前逻辑部分仅支持javascript语言,并使用wxml(类似html)和wxss(类似css)来描述页面的结构和样式。此处的javascript和web中是完全一样的,但因为不是运行在浏览器环境中,因此无法使用 windows,document等对象,自然也无法使用jquery等第三方库。而wxml,wxss的语法和html,css也是十分相近的。
页面也同样可以包含一个index.json文件用于配置,不过这不是必须的。
通常一个完整的微信小程序包含上面两部分,当然我们也可以定义自己的目录用于存放公共代码和程序需要的其它文件。
app.json
打开app.json文件,可以看到如下代码
{ "pages":[ "pages/index/index", "pages/logs/logs" ], "window":{ "backgroundTextStyle":"light", "navigationBarBackgroundColor": "#fff", "navigationBarTitleText": "WeChat", "navigationBarTextStyle":"black" } }
其中pages部分包含了程序的页面,这样框架就能知道从哪里找到页面文件。而window部分包含了程序窗口的一些配置。详细的配置项可以参考配置 小程序
app.wxss
app.wxss文件包含了全局的样式信息,在默认生成的程序中,只有一个类选择器.container,该类型在index.wxml和 logs.wxml中有使用到。
app.js
该文件包含了程序的主体流程代码实现,关于该部分的分析请见下一篇教程。
The above is the detailed content of Structural Overview of the Basics of WeChat Mini Program Development (2). For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics





Xianyu's official WeChat mini program has quietly been launched. In the mini program, you can post private messages to communicate with buyers/sellers, view personal information and orders, search for items, etc. If you are curious about what the Xianyu WeChat mini program is called, take a look now. What is the name of the Xianyu WeChat applet? Answer: Xianyu, idle transactions, second-hand sales, valuations and recycling. 1. In the mini program, you can post idle messages, communicate with buyers/sellers via private messages, view personal information and orders, search for specified items, etc.; 2. On the mini program page, there are homepage, nearby, post idle, messages, and mine. 5 functions; 3. If you want to use it, you must activate WeChat payment before you can purchase it;

WeChat applet implements picture upload function With the development of mobile Internet, WeChat applet has become an indispensable part of people's lives. WeChat mini programs not only provide a wealth of application scenarios, but also support developer-defined functions, including image upload functions. This article will introduce how to implement the image upload function in the WeChat applet and provide specific code examples. 1. Preparatory work Before starting to write code, we need to download and install the WeChat developer tools and register as a WeChat developer. At the same time, you also need to understand WeChat

To implement the drop-down menu effect in WeChat Mini Programs, specific code examples are required. With the popularity of mobile Internet, WeChat Mini Programs have become an important part of Internet development, and more and more people have begun to pay attention to and use WeChat Mini Programs. The development of WeChat mini programs is simpler and faster than traditional APP development, but it also requires mastering certain development skills. In the development of WeChat mini programs, drop-down menus are a common UI component, achieving a better user experience. This article will introduce in detail how to implement the drop-down menu effect in the WeChat applet and provide practical

Implementing picture filter effects in WeChat mini programs With the popularity of social media applications, people are increasingly fond of applying filter effects to photos to enhance the artistic effect and attractiveness of the photos. Picture filter effects can also be implemented in WeChat mini programs, providing users with more interesting and creative photo editing functions. This article will introduce how to implement image filter effects in WeChat mini programs and provide specific code examples. First, we need to use the canvas component in the WeChat applet to load and edit images. The canvas component can be used on the page

Use the WeChat applet to achieve the carousel switching effect. The WeChat applet is a lightweight application that is simple and efficient to develop and use. In WeChat mini programs, it is a common requirement to achieve carousel switching effects. This article will introduce how to use the WeChat applet to achieve the carousel switching effect, and give specific code examples. First, add a carousel component to the page file of the WeChat applet. For example, you can use the <swiper> tag to achieve the switching effect of the carousel. In this component, you can pass b

The official WeChat mini program of Xianyu has been quietly launched. It provides users with a convenient platform that allows you to easily publish and trade idle items. In the mini program, you can communicate with buyers or sellers via private messages, view personal information and orders, and search for the items you want. So what exactly is Xianyu called in the WeChat mini program? This tutorial guide will introduce it to you in detail. Users who want to know, please follow this article and continue reading! What is the name of the Xianyu WeChat applet? Answer: Xianyu, idle transactions, second-hand sales, valuations and recycling. 1. In the mini program, you can post idle messages, communicate with buyers/sellers via private messages, view personal information and orders, search for specified items, etc.; 2. On the mini program page, there are homepage, nearby, post idle, messages, and mine. 5 functions; 3.

Implementing the sliding delete function in WeChat mini programs requires specific code examples. With the popularity of WeChat mini programs, developers often encounter problems in implementing some common functions during the development process. Among them, the sliding delete function is a common and commonly used functional requirement. This article will introduce in detail how to implement the sliding delete function in the WeChat applet and give specific code examples. 1. Requirements analysis In the WeChat mini program, the implementation of the sliding deletion function involves the following points: List display: To display a list that can be slid and deleted, each list item needs to include

To implement the picture rotation effect in WeChat Mini Program, specific code examples are required. WeChat Mini Program is a lightweight application that provides users with rich functions and a good user experience. In mini programs, developers can use various components and APIs to achieve various effects. Among them, the picture rotation effect is a common animation effect that can add interest and visual effects to the mini program. To achieve image rotation effects in WeChat mini programs, you need to use the animation API provided by the mini program. The following is a specific code example that shows how to
