安装
需要先安装 Node.js 环境,然后通过官方模版安装脚手架:
npx degit dcloudio/uni-preset-vue#vite uniapp-demo
安装好框架代码后安装依赖:
cd uniapp-demo
npm install
快速开始
UniApp 采用 Vue 的语法,可以像开发 Vue 应用那样进行开发,这里提供一个简单示例。
修改pages\index\index.vue:
<template>
<view class="content">
<image class="logo" src="/static/logo.png"></image>
<view class="text-area">
<text class="title"></text>
</view>
<view></view>
<view class="text-area">
<button @click="plus">+</button>
<button @click="minus">-</button>
</view>
</view>
</template>
<script setup>
import { ref } from 'vue';
const title = ref("hello")
const num = ref(0)
function plus() {
num.value++
}
function minus() {
num.value--
}
</script>
UniApp 支持跨平台,因此测试/打包时需要指定目标平台,比如以 H5 应用的方式运行:
npm run dev:h5
The End.

文章评论