红茶的个人站点

  • 首页
  • 专栏
  • 开发工具
  • 其它
  • 隐私政策
Awalon
Talk is cheap,show me the code.
  1. 首页
  2. 开发工具
  3. 正文

UniApp 简易指南

2026年1月28日 6点热度 0人点赞 0条评论

安装

需要先安装 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">{{ title }}</text>
    </view>
    <view>{{ num }}</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.

参考资料

  • uni-app官网

  • UniApp 教程

本作品采用 知识共享署名 4.0 国际许可协议 进行许可
标签: uniapp vue
最后更新:2026年1月28日

魔芋红茶

加一点PHP,加一点Go,加一点Python......

点赞
< 上一篇

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

COPYRIGHT © 2021 icexmoon.cn. ALL RIGHTS RESERVED.
本网站由提供CDN加速/云存储服务

Theme Kratos Made By Seaton Jiang

宁ICP备2021001508号

宁公网安备64040202000141号