


Summarize and share the development specifications for uniapp development applet

1. Project structure
<p>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.
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
Component and interface specifications
<p>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 <p><view>
tag has the same meaning in uniapp as the <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<p>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 specification3. css style specification
Global style and local style
<p>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>
尺寸响应式
<p>uniapp框架为了更好的适配不同的移动端屏幕,设置了750rpx为屏幕的基准宽度。如果屏幕宽度小,rpx显示效果会等比缩小;如果屏幕宽度大,rpx显示效果会等比例放大。举例说明: 如果设计稿的元素宽度是600px,某元素X的宽度是100px,那么该元素X在uniapp里面设置的宽度应该是:750 * 100 /600 = 125rpx。<p>如果大家觉得自己手动计算比较麻烦,可以在文件manifest.json
中设置transformPx
的值为true,项目会自动将px
转换为rpx
。字体的使用
<p>uniapp支持字体的引用方式分为2种情况,如果字体文件小于 40kb,uniapp会自动将其转化为 base64 格式;将字体文件放置到static目录下,然后通过font-face定义字体。@font-face { font-family: 'test-icon'; src: url('~@/static/iconfont.ttf'); }
@font-face { font-family: 'test-icon'; font-weight: normal; font-style: normal; src: url(data:font/truetype;charset=utf-8;base64,转换的base64内容) format('truetype'); }
font-family
即可。
请使用flex布局方式
<p>为更好的支持跨平台,uniapp框架建议使用css的Flex方式布局。 <p>推荐:《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!

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

AI Hentai Generator
Generate AI Hentai for free.

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



Steps to launch UniApp project preview in WebStorm: Install UniApp Development Tools plugin Connect to device settings WebSocket launch preview

Generally speaking, uni-app is better when complex native functions are needed; MUI is better when simple or highly customized interfaces are needed. In addition, uni-app has: 1. Vue.js/JavaScript support; 2. Rich native components/API; 3. Good ecosystem. The disadvantages are: 1. Performance issues; 2. Difficulty in customizing the interface. MUI has: 1. Material Design support; 2. High flexibility; 3. Extensive component/theme library. The disadvantages are: 1. CSS dependency; 2. Does not provide native components; 3. Small ecosystem.

uniapp development requires the following foundations: front-end technology (HTML, CSS, JavaScript) mobile development knowledge (iOS and Android platforms) Node.js other foundations (version control tools, IDE, mobile development simulator or real machine debugging experience)

UniApp has many conveniences as a cross-platform development framework, but its shortcomings are also obvious: performance is limited by the hybrid development mode, resulting in poor opening speed, page rendering, and interactive response. The ecosystem is imperfect and there are few components and libraries in specific fields, which limits creativity and the realization of complex functions. Compatibility issues on different platforms are prone to style differences and inconsistent API support. The security mechanism of WebView is different from native applications, which may reduce application security. Application releases and updates that support multiple platforms at the same time require multiple compilations and packages, increasing development and maintenance costs.

When choosing between UniApp and native development, you should consider development cost, performance, user experience, and flexibility. The advantages of UniApp are cross-platform development, rapid iteration, easy learning and built-in plug-ins, while native development is superior in performance, stability, native experience and scalability. Weigh the pros and cons based on specific project needs. UniApp is suitable for beginners, and native development is suitable for complex applications that pursue high performance and seamless experience.

UniApp is based on Vue.js, and Flutter is based on Dart. Both support cross-platform development. UniApp provides rich components and easy development, but its performance is limited by WebView; Flutter uses a native rendering engine, which has excellent performance but is more difficult to develop. UniApp has an active Chinese community, and Flutter has a large and global community. UniApp is suitable for scenarios with rapid development and low performance requirements; Flutter is suitable for complex applications with high customization and high performance.

Recommended component library for uniapp to develop small programs: uni-ui: Officially produced by uni, it provides basic and business components. vant-weapp: Produced by Bytedance, with a simple and beautiful UI design. taro-ui: produced by JD.com and developed based on the Taro framework. fish-design: Produced by Baidu, using Material Design design style. naive-ui: Produced by Youzan, modern UI design, lightweight and easy to customize.
