English
In order to improve development efficiency, HBuilderX encapsulates the common code of uni-app
into code blocks starting with u
. For example, enter ulist
in the template
tag and press Enter, the following code will be automatically generated:
<uni-list>
<uni-list-item title="" note=""></uni-list-item>
<uni-list-item title="" note=""></uni-list-item>
</uni-list>
Note: Make sure the uni-list
component is saved in the components
directory of the project. A simpler way is to select the uni-ui
project template when creating a new project, and you can type all the code blocks starting with u in it. If your project is not a uni-ui
project template, then you need to go to the plugin market to manually download uni ui components into the project.
Code blocks are divided into Tag
code blocks and JS
code blocks. If you enter uShowToast
in the script
tag and press Enter, the following code will be automatically generated:
uni.showToast({
title: '',
mask: false,
duration: 1500
});
uni-app
supports code blocks as listed below.
Almost all components, whether they are built-in components or uni-ui
components, have been encapsulated as code blocks; use HBuilderX
to open the .vue
file in the uni-app
project, and type in the
templatearea u
, Code Assistant prompts for a list of all visible code blocks.
You can also view all supported code blocks in the left list of HBuilderX menu - Tools - Code Block Settings - Vue Code Blocks.
In addition to components, other common code blocks include:
Almost all common js apis have been encapsulated as code blocks. Type u in the js code of HBuilderX, and the code assistant will prompt all visible lists. You can also view all of them in the left list of HBuilderX menu-tools-code block settings-js code block.
If the preset code block does not meet the requirements, you can customize the code block. Refer to the tutorial https://ask.dcloud.net.cn/article/35924