2 Star 5 Fork 4

有来开源组织/uniapp-nutui-template

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

项目依赖

导入基础模板

通过 HBuilderX 导入项目 https://gitee.com/h_mo/uniapp-vue3-vite-ts-template

image-20240226233320600

模板整合 nutui

参考文档:https://nutui-uniapp.netlify.app/guide/quick-start.html

npm 安装

pnpm add nutui-uniapp

组件 TS 类型支持

在 tsconfig.json 中通过 compilerOptions.type 指定全局组件类型。

// tsconfig.json
{
    "compilerOptions": {
        // ...
        "types": ["nutui-uniapp/global.d.ts"]
    }
}

自动导入

安装 vite-plugin-uni-components, 安装和使用说明

pnpm i -D @uni-helper/vite-plugin-uni-components

配置 vite.config.ts

// Vite中文网:https://vitejs.cn/config/
import { ConfigEnv, loadEnv, UserConfig } from 'vite';
import { resolve } from 'path';
import uni from '@dcloudio/vite-plugin-uni';
import Components from '@uni-helper/vite-plugin-uni-components';
import { NutResolver } from 'nutui-uniapp';

// https://vitejs.dev/config/
export default ({ mode }: ConfigEnv): UserConfig => {
    const root = process.cwd();
    const env = loadEnv(mode, root);
    return {
        // ...
        plugins: [
            // ...
            Components({
                resolvers: [NutResolver()],
                dirs: ['src/components', 'src/**/components'],
                dts: 'typings/components.d.ts',
            }),
            // uni 插件一定要放到后面
            uni(),
        ],
    };
};

如果你使用 pnpm ,请在根目录下创建一个 .npmrc 文件,参见issue

// .npmrc
public-hoist-pattern[]=@vue*
// or
// shamefully-hoist = true

样式引入

在项目文件 app.vue 文件中添加如下代码:

// App.vue
<style lang="scss">
    @import 'nutui-uniapp/styles/index';
</style>

导入样式变量

// vite.config.ts
import { defineConfig } from 'vite';

// https://vitejs.dev/config/
export default defineConfig({
    // ...
    css: {
        preprocessorOptions: {
            scss: {
                additionalData: '@import "nutui-uniapp/styles/variables.scss";',
            },
        },
    },
});

测试示例

<!-- pages/index/index.vue -->
<template>
    <AppProvider>
        <view class="content">
            <nut-button type="primary"> 主要按钮 </nut-button>
            <!-- ... -->
        </view>
    </AppProvider>
</template>

image-20240227003711245

UnoCSS

pnpm i -D @unocss/transformer-directives
MIT License Copyright (c) 2022 h_mo Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

uniapp + nutui 移动端/小程序/H5模板工程 展开 收起
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/youlaiorg/uniapp-nutui-template.git
git@gitee.com:youlaiorg/uniapp-nutui-template.git
youlaiorg
uniapp-nutui-template
uniapp-nutui-template
master

搜索帮助

Cb406eda 1850385 E526c682 1850385