Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

UniApp Environment Setup

UniApp Environment Setup

UniApp is a framework that uses Vue.js to develop all front-end applications; developers write one codebase and can publish to iOS, Android, Web (responsive), and various mini programs (WeChat / Alipay / Baidu / Toutiao / Feishu / QQ / Kuaishou / DingTalk / Taobao), quick apps and other platforms.

uni-app supports creating projects quickly in two ways: through a visual interface and through the vue-cli command line.


Installing and configuring the HBuilderX development tool

HBuilderX, H is the first letter of HTML, Builder means constructor, and X is the next generation of HBuilder. We also call it simplyHX.
HXIsLight as an editor, powerful as an IDEa combined version of both.

HBuilderX has the relevant environment built in and works out of the box, with no need to configure nodejs.

Download and install:

  1. Visit the official site:https://www.dcloud.io/hbuilderx.html
  2. Choose the version for your operating system (Windows/macOS/Linux)

After downloading and installing, we can set our preferred theme:

Create a UniApp project

Click File -> New -> Project in the toolbar (shortcut Ctrl+N):

Select the uni-app type, enter the project name, choose a template, and click Create to create it successfully.

Templates bundled with uni-app include the default empty project template, the Hello uni-app official components and API examples, and an important one, the uni ui project template; this template is recommended for daily development as it includes many commonly used components.

Run uni-app

Run in a browser: enter the project, click Run -> Run to Browser -> Choose Browser in the toolbar, select Chrome or another browser, and you can try the web version of uni-app.

Run an App on a phone or emulator: connect the phone with a USB port providing sufficient voltage, enable USB debugging in settings, allow the computer to debug the phone, enter the project, click Run -> Run App to Phone or Emulator in the toolbar, and you can try uni-app on that device.

Run in WeChat DevTools: enter the project, click Run -> Run to Mini Program Simulator -> WeChat DevTools in the toolbar, and you can try uni-app in WeChat DevTools.

**Note:** if this is your first time, you need to configure the mini program IDE path before it can run successfully. As shown below, enter the installation path of WeChat DevTools in the input box.

**Note:** WeChat DevTools needs the service port enabled under Settings -> Security in the WeChat tool.

Run in Alipay Mini Program DevTools: enter the project, click Run -> Run to Mini Program Simulator -> Alipay Mini Program DevTools in the toolbar, and you can try uni-app in Alipay Mini Program DevTools.

Run in the developer tools for Baidu, Douyin, QQ, Quick App (Alliance and Huawei), Kuaishou, Feishu, 360, JD and other mini programs: same as above, not repeated here.

Note:

The shortcut for running is Ctrl+R.

HBuilderX also provides a quick-run menu so you can press a number to quickly choose the device to run on:


Creating with the Vue cli command

Besides the HBuilderX visual interface, you can also create uni-app projects through vue-cli.

Create a uni-app project

Create a Vue 3 project

Create a project developed in JavaScript:



npx degit dcloudio/uni-preset-vue#vite my-vue3-project



npx degit dcloudio/uni-preset-vue#vite-alpha my-vue3-project

Create a project developed in TypeScript



npx degit dcloudio/uni-preset-vue#vite-ts my-vue3-project

Create a Vue 2 project

Requires a global vue-cli installation: npm install -g @vue/cli

Use the official release (corresponding to the latest official HBuilderX release)



vue create -p dcloudio/uni-preset-vue my-project

Use the alpha version (corresponding to the latest HBuilderX alpha release)



vue create -p dcloudio/uni-preset-vue#alpha my-alpha-project

At this point you will be prompted to choose a project template (the Vue3/Vite version does not prompt and currently only supports creating the default template); for a first try, the hello uni-app template is recommended, as shown below:


For more information, refer to: