Skip to content

Commit 3254c85

Browse files
author
liuq
authored
Merge pull request #2 from aliuq/feat-naive-ui
feat: add naive-ui ssr example
2 parents 40fc0ca + 272a96f commit 3254c85

File tree

16 files changed

+1135
-0
lines changed

16 files changed

+1135
-0
lines changed

examples/naive-ui/.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
dist
12+
dist-ssr
13+
*.local
14+
15+
# Editor directories and files
16+
.vscode/*
17+
!.vscode/extensions.json
18+
.idea
19+
.DS_Store
20+
*.suo
21+
*.ntvs*
22+
*.njsproj
23+
*.sln
24+
*.sw?

examples/naive-ui/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Vue 3 + Typescript + Vite
2+
3+
This template should help get you started developing with Vue 3 and Typescript in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
4+
5+
## Recommended IDE Setup
6+
7+
- [VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=johnsoncodehk.volar)
8+
9+
## Type Support For `.vue` Imports in TS
10+
11+
Since TypeScript cannot handle type information for `.vue` imports, they are shimmed to be a generic Vue component type by default. In most cases this is fine if you don't really care about component prop types outside of templates. However, if you wish to get actual prop types in `.vue` imports (for example to get props validation when using manual `h(...)` calls), you can enable Volar's `.vue` type support plugin by running `Volar: Switch TS Plugin on/off` from VSCode command palette.

examples/naive-ui/components.d.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// generated by unplugin-vue-components
2+
// We suggest you to commit this file into source control
3+
// Read more: https://github.com/vuejs/vue-next/pull/3399
4+
5+
declare module 'vue' {
6+
export interface GlobalComponents {
7+
HelloWorld: typeof import('./src/components/HelloWorld.vue')['default']
8+
NButton: typeof import('naive-ui')['NButton']
9+
NCheckbox: typeof import('naive-ui')['NCheckbox']
10+
NCheckboxGroup: typeof import('naive-ui')['NCheckboxGroup']
11+
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
12+
NDatePicker: typeof import('naive-ui')['NDatePicker']
13+
NForm: typeof import('naive-ui')['NForm']
14+
NFormItem: typeof import('naive-ui')['NFormItem']
15+
NFormItemGi: typeof import('naive-ui')['NFormItemGi']
16+
NGrid: typeof import('naive-ui')['NGrid']
17+
NInput: typeof import('naive-ui')['NInput']
18+
NInputNumber: typeof import('naive-ui')['NInputNumber']
19+
NMessageProvider: typeof import('naive-ui')['NMessageProvider']
20+
NRadio: typeof import('naive-ui')['NRadio']
21+
NRadioButton: typeof import('naive-ui')['NRadioButton']
22+
NRadioGroup: typeof import('naive-ui')['NRadioGroup']
23+
NSelect: typeof import('naive-ui')['NSelect']
24+
NSlider: typeof import('naive-ui')['NSlider']
25+
NSpace: typeof import('naive-ui')['NSpace']
26+
NSwitch: typeof import('naive-ui')['NSwitch']
27+
NTimePicker: typeof import('naive-ui')['NTimePicker']
28+
NTransfer: typeof import('naive-ui')['NTransfer']
29+
}
30+
}
31+
32+
export { }

examples/naive-ui/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" href="/favicon.ico" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Vue 3 | TS | Vite | NaiveUI</title>
8+
</head>
9+
<body>
10+
<div id="app"></div>
11+
<script type="module" src="/src/main.ts"></script>
12+
</body>
13+
</html>

examples/naive-ui/package.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "naive-ui",
3+
"version": "0.0.0",
4+
"private": true,
5+
"scripts": {
6+
"dev": "vite-ssr --port 3000",
7+
"build": "vite-ssr build",
8+
"serve": "cross-env NODE_ENV=production vite-ssr"
9+
},
10+
"dependencies": {
11+
"vue": "^3.2.25",
12+
"vue-router": "^4.0.13"
13+
},
14+
"devDependencies": {
15+
"@css-render/vue3-ssr": "^0.15.9",
16+
"@vitejs/plugin-vue": "^2.2.0",
17+
"cross-env": "^7.0.3",
18+
"naive-ui": "^2.26.4",
19+
"typescript": "^4.5.4",
20+
"unplugin-vue-components": "^0.17.21",
21+
"vite": "^2.8.0",
22+
"vite-ssr-vue3": "workspace:^0.0.4",
23+
"vue-tsc": "^0.29.8"
24+
}
25+
}

examples/naive-ui/public/favicon.ico

4.19 KB
Binary file not shown.

examples/naive-ui/src/App.vue

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<script setup lang="ts">
2+
// This starter template is using Vue 3 <script setup> SFCs
3+
// Check out https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup
4+
import { darkTheme, lightTheme } from 'naive-ui'
5+
import { ref } from 'vue'
6+
import HelloWorld from './components/HelloWorld.vue'
7+
8+
const theme = ref<typeof darkTheme | null>(null)
9+
const toggleTheme = () => {
10+
theme.value = theme.value?.name === 'dark' ? lightTheme : darkTheme
11+
}
12+
</script>
13+
14+
<template>
15+
<n-message-provider>
16+
<n-config-provider :theme="theme">
17+
<div class="icons">
18+
<img alt="Vue logo" src="./assets/logo.png">
19+
<span>+</span>
20+
<img src="https://www.naiveui.com/assets/naivelogo.93278402.svg" alt="">
21+
</div>
22+
<div class="form">
23+
<h2>
24+
Form 示例 <n-button @click="toggleTheme">
25+
深色/浅色
26+
</n-button>
27+
</h2>
28+
<HelloWorld />
29+
</div>
30+
</n-config-provider>
31+
</n-message-provider>
32+
</template>
33+
34+
<style>
35+
#app {
36+
-webkit-font-smoothing: antialiased;
37+
-moz-osx-font-smoothing: grayscale;
38+
39+
width: 800px;
40+
margin: 60px auto;
41+
}
42+
.icons {
43+
display: flex;
44+
align-items: center;
45+
justify-content: center;
46+
padding: 0.5rem;
47+
height: 150px;
48+
}
49+
.icons img {
50+
height: 100%;
51+
object-fit: cover;
52+
}
53+
.icons span {
54+
font-size: 60px;
55+
padding: 0 2rem;
56+
color: #666;
57+
}
58+
.form h2 {
59+
margin-bottom: 2rem;
60+
}
61+
</style>

examples/naive-ui/src/assets/logo.png

6.69 KB
Loading

0 commit comments

Comments
 (0)