


Summarize and share the development specifications for uniapp development applet
This article brings you relevant knowledge about uniappcross-domain. uni-app is a front-end framework that uses vue.js to develop cross-platform applications. The following is an introduction to the development of small programs with uniapp Development specifications, I hope it will be helpful to everyone.
Recommended: "uniapp tutorial"
1. Project structure
After completing the creation of the uniapp project , its project directory structure is as follows. Let’s give a brief introduction to the project structure below. If you still can’t understand it after reading the introduction, I suggest you learn Vue first. Because uniapp is developed based on the core syntax of Vue, learning Vue is necessary.
- .hbuilderx is the development configuration directory of HBuilderX, the tool used to develop this project. Generally, there is no need to manually modify its contents. With this directory, when others import the project, your development tool configuration information will be used by default. Because everyone has different habits in using development tools, this directory is generally not uploaded to the version management warehouse.
- pages is the storage directory for all vue pages. You can create subdirectories under the pages directory according to your own plans.
- The static directory usually stores static resources referenced by the project, such as: pictures, icons, fonts Wait for
- unpackage to store the packaging files of each platform, and the result files after project packaging will be stored in this directory.
- App.vue is the root component of the project, which is the Vue single-page entry file. Application-level life cycle functions can be monitored on this page.
- main.js is the js entry file of the project, which instantiates the vue page and integrates the component plug-ins and other content required by the vue page.
- index.html is the home page of the project and the entry page of the project. The Vue page result after main.js is instantiated will eventually be rendered to the home page.
- Manifest.json is the application configuration file, used to specify the application name, icon, permissions, startup page settings, plug-ins and other information.
- pages.json configures the display page of the application, such as file path, window style, native navigation bar configuration, etc.
- The uni.scss file is mainly used to control the overall display style of the application page. It presets some SCSS variables, such as text color, background color, border color, picture size, etc.
Finally, generally speaking, we also need to manually create a components
directory to store the components components of vue.
2. Development specifications
Follow the Vue Single File Component (SFC) specification
<template> <view class="content"> <image class="logo" src="/static/logo.png"></image> <view class="text-area"> <text class="title">{{title}}</text> </view> </view> </template> <script> export default { data() { return { title: 'Hello' } }, onLoad() { }, methods: { } } </script> <style> //这里可以书写css、sass、less等样式及样式预处理器 </style>
- A vue file can only contain one top-level
<template></template>
Template - A vue file can only contain one
<script></script>
Script definition - A vue file can contain one or more
<style></style>
Style definition
The page development of uniapp follows the Vue Single File Component (SFC) ) specification. In addition, uniapp cannot use js to perform DOM operations on HTML documents. Please strictly follow Vue's MVVM data binding development method.
Component and interface specifications
It should be noted that standard html tags cannot be used in uniapp. The definition of uniapp component names and usage methods is closer to the WeChat applet. Please refer to: uni- For app component documentation, you can refer to the WeChat applet component documentation for assistance. For example: The
<view></view>
tag has the same meaning in uniapp as the <p></p>
tag in standard HTML. If you want to define an image, you cannot directly To use img in html, you should use the component tag image of uniapp
uniapp’s interface capability (JS API) is very close to the WeChat applet specification, but the prefix wx
needs to be replaced with uni
, for details, see uni-app interface specification
3. css style specification
Global style and local style
uni.scss
Some global style scss variables are preset in the file. These variables are used to define the overall style of the application, such as text color, background color, border color, etc. It should be noted that this file should not be modified at will. If you want to change it, you can only modify the value of the variable, and do not modify the name of the variable. So if we want to add some customized global styles, how should we do it? Refer to the following method:
- First, write a style file yourself, such as: app.scss, and write custom styles in this file. Place the file in the /static/style directory
- Secondly, at the beginning of the app.scss file, introduce the uni.scss file. The introduction statement is: @import '~@/uni.scss';
- Finally, introduce this custom global style file into the style of App and vue
<style> @import '~@/static/style/app.scss'; </style>
The local style implementation of uniapp is based on vue files and is defined in a certain vue file. The style only takes effect within the rendering range of the vue.
尺寸响应式
uniapp框架为了更好的适配不同的移动端屏幕,设置了750rpx为屏幕的基准宽度。如果屏幕宽度小,rpx显示效果会等比缩小;如果屏幕宽度大,rpx显示效果会等比例放大。举例说明: 如果设计稿的元素宽度是600px,某元素X的宽度是100px,那么该元素X在uniapp里面设置的宽度应该是:750 * 100 /600 = 125rpx。
如果大家觉得自己手动计算比较麻烦,可以在文件manifest.json
中设置transformPx
的值为true,项目会自动将px
转换为rpx
。
字体的使用
uniapp支持字体的引用方式分为2种情况,如果字体文件小于 40kb,uniapp会自动将其转化为 base64 格式;将字体文件放置到static目录下,然后通过font-face定义字体。
@font-face { font-family: 'test-icon'; src: url('~@/static/iconfont.ttf'); }
如果字体文件大于等于 40kb, 需开发者自己转换将字体文件转换成Base64字符串,否则使用将不生效;将转换之后的Base64字符串粘贴到下文的位置,完成字体的定义。
@font-face { font-family: 'test-icon'; font-weight: normal; font-style: normal; src: url(data:font/truetype;charset=utf-8;base64,转换的base64内容) format('truetype'); }
字体的使用方式是通用的css样式,使用font-family
即可。
请使用flex布局方式
为更好的支持跨平台,uniapp框架建议使用css的Flex方式布局。
推荐:《uniapp教程》
The above is the detailed content of Summarize and share the development specifications for uniapp development applet. For more information, please follow other related articles on the PHP Chinese website!

The article discusses debugging strategies for mobile and web platforms, highlighting tools like Android Studio, Xcode, and Chrome DevTools, and techniques for consistent results across OS and performance optimization.

The article discusses debugging tools and best practices for UniApp development, focusing on tools like HBuilderX, WeChat Developer Tools, and Chrome DevTools.

The article discusses end-to-end testing for UniApp applications across multiple platforms. It covers defining test scenarios, choosing tools like Appium and Cypress, setting up environments, writing and running tests, analyzing results, and integrat

The article discusses various testing types for UniApp applications, including unit, integration, functional, UI/UX, performance, cross-platform, and security testing. It also covers ensuring cross-platform compatibility and recommends tools like Jes

The article discusses common performance anti-patterns in UniApp development, such as excessive global data use and inefficient data binding, and offers strategies to identify and mitigate these issues for better app performance.

The article discusses using profiling tools to identify and resolve performance bottlenecks in UniApp, focusing on setup, data analysis, and optimization.

The article discusses strategies for optimizing network requests in UniApp, focusing on reducing latency, implementing caching, and using monitoring tools to enhance application performance.

The article discusses optimizing images in UniApp for better web performance through compression, responsive design, lazy loading, caching, and using WebP format.


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

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

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

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

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.

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.