This commit is contained in:
algerkong
2021-07-19 17:36:48 +08:00
commit 4d1d44b0ae
21 changed files with 2446 additions and 0 deletions

5
.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
node_modules
.DS_Store
dist
dist-ssr
*.local

27
README.md Normal file
View File

@@ -0,0 +1,27 @@
# Vue 3 + Typescript + Vite
This template should help get you started developing with Vue 3 and Typescript in Vite.
## Recommended IDE Setup
[VSCode](https://code.visualstudio.com/) + [Vetur](https://marketplace.visualstudio.com/items?itemName=octref.vetur). Make sure to enable `vetur.experimental.templateInterpolationService` in settings!
### If Using `<script setup>`
[`<script setup>`](https://github.com/vuejs/rfcs/pull/227) is a feature that is currently in RFC stage. To get proper IDE support for the syntax, use [Volar](https://marketplace.visualstudio.com/items?itemName=johnsoncodehk.volar) instead of Vetur (and disable Vetur).
## Type Support For `.vue` Imports in TS
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 use the following:
### If Using Volar
Run `Volar: Switch TS Plugin on/off` from VSCode command palette.
### If Using Vetur
1. Install and add `@vuedx/typescript-plugin-vue` to the [plugins section](https://www.typescriptlang.org/tsconfig#plugins) in `tsconfig.json`
2. Delete `src/shims-vue.d.ts` as it is no longer needed to provide module info to Typescript
3. Open `src/main.ts` in VSCode
4. Open the VSCode command palette
5. Search and run "Select TypeScript version" -> "Use workspace version"

17
index.html Normal file
View File

@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
<link rel="stylesheet" href="//at.alicdn.com/t/font_2685283_g37f9g4ikw8.css">
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>

2065
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

29
package.json Normal file
View File

@@ -0,0 +1,29 @@
{
"version": "0.0.0",
"scripts": {
"dev": "vite",
"build": "vue-tsc --noEmit && vite build",
"serve": "vite preview"
},
"dependencies": {
"@tailwindcss/postcss7-compat": "^2.2.4",
"autoprefixer": "^9.8.6",
"postcss": "^7.0.36",
"sass": "^1.35.2",
"tailwindcss": "npm:@tailwindcss/postcss7-compat@^2.2.4",
"vue": "^3.0.5",
"vue-router": "^4.0.10",
"vuex": "^4.0.2"
},
"devDependencies": {
"@sicons/antd": "^0.10.0",
"@vicons/antd": "^0.10.0",
"@vitejs/plugin-vue": "^1.2.3",
"@vue/compiler-sfc": "^3.0.5",
"naive-ui": "^2.15.5",
"typescript": "^4.3.2",
"vfonts": "^0.1.0",
"vite": "^2.3.8",
"vue-tsc": "^0.0.24"
}
}

6
postcss.config.js Normal file
View File

@@ -0,0 +1,6 @@
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}

BIN
public/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

15
src/App.vue Normal file
View File

@@ -0,0 +1,15 @@
<template>
<div>
<router-view></router-view>
</div>
</template>
<script lang="ts" setup>
</script>
<style lang="scss" scoped >
div {
box-sizing: border-box;
}
</style>

BIN
src/assets/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

6
src/index.css Normal file
View File

@@ -0,0 +1,6 @@
/* ./src/index.css */
/*! @import */
@tailwind base;
@tailwind components;
@tailwind utilities;

106
src/layout/AppLayout.vue Normal file
View File

@@ -0,0 +1,106 @@
<template>
<div class="layout-page">
<div class="layout-main">
<app-menu class="menu" :menus="menus" />
<router-view class="main"></router-view>
</div>
</div>
</template>
<script lang="ts" setup>
import { ref } from '@vue/reactivity';
import { AppMenu } from './components';
let menus = ref([
{
href: '/',
icon: "icon-homefill",
text: "hello"
},
{
href: '/main',
icon: "icon-peoplefill",
text: "hello"
},
{
href: '/',
icon: "icon-homefill",
text: "hello"
},
{
href: '/main',
icon: "icon-peoplefill",
text: "hello"
},
{
href: '/',
icon: "icon-homefill",
text: "hello"
},
{
href: '/main',
icon: "icon-peoplefill",
text: "hello"
},
{
href: '/',
icon: "icon-homefill",
text: "hello"
},
{
href: '/main',
icon: "icon-peoplefill",
text: "hello"
},
{
href: '/',
icon: "icon-homefill",
text: "hello"
},
{
href: '/main',
icon: "icon-peoplefill",
text: "hello"
},
{
href: '/',
icon: "icon-videofill",
text: "hello"
},
{
href: '/',
icon: "icon-videofill",
text: "hello"
},
{
href: '/',
icon: "icon-videofill",
text: "hello"
},
{
href: '/',
icon: "icon-videofill",
text: "hello"
}
])
</script>
<style lang="scss" scoped>
.layout-page {
width: 100vw;
height: 100vh;
@apply flex justify-center items-center;
}
.layout-main {
@apply bg-black rounded-lg mb-10 text-white shadow-xl flex;
height: 800px;
width: 1400px;
.menu {
width: 70px;
}
.main {
@apply p-4;
flex: 1;
}
}
</style>

View File

@@ -0,0 +1,67 @@
<template>
<div>
<!-- menu -->
<div class="app-menu">
<div class="app-menu-header">
<div class="app-menu-logo">
<img src="@/assets/logo.png" class="w-10 h-10" alt="logo" />
</div>
</div>
<div class="app-menu-list">
<div class="app-menu-item" v-for="(item,index) in menus" :key="index">
<router-link class="app-menu-item-link mb-4 mt-4" :to="item.href">
<i class="iconfont app-menu-item-icon" :style="iconStyle" :class="item.icon"></i>
<span v-if="isText" class="app-menu-item-text ml-3">{{ item.text }}</span>
</router-link>
</div>
</div>
</div>
</div>
</template>
<script lang="ts" setup>
import { onMounted, ref } from "@vue/runtime-core";
const props = defineProps({
isText: {
type: Boolean,
default: false
},
size: {
type: String,
default: '30px'
},
color: {
type: String,
default: '#fff'
},
menus: {
type: Array,
default: () => []
}
})
let iconStyle = ref({})
onMounted(() => {
// 初始化
iconStyle.value = {
fontSize: props.size,
color: props.color
}
})
</script>
<style lang="scss" scoped>
.app-menu {
@apply flex-col items-center justify-center p-4;
max-width: 100px;
}
.app-menu-item-link,
.app-menu-header {
@apply flex items-center justify-center;
}
img {
color: #fff;
}
</style>

View File

@@ -0,0 +1,3 @@
import AppMenu from "./AppMenu.vue";
export { AppMenu };

16
src/main.ts Normal file
View File

@@ -0,0 +1,16 @@
import { createApp } from "vue";
import App from "./App.vue";
import naive from "naive-ui";
import "vfonts/Lato.css";
import "vfonts/FiraCode.css";
// tailwind css
import "./index.css";
import router from "@/router";
const app = createApp(App);
app.use(router);
app.use(naive);
app.mount("#app");

22
src/router/index.ts Normal file
View File

@@ -0,0 +1,22 @@
import { createRouter, createWebHistory } from "vue-router";
import AppLayout from "@/layout/AppLayout.vue";
const layoutRouter = [
{
path: "",
name: "home",
component: () => import("@/views/home/index.vue"),
},
];
const routes = [
{
path: "/",
component: AppLayout,
children: layoutRouter,
},
];
export default createRouter({
routes: routes,
history: createWebHistory(),
});

5
src/shims-vue.d.ts vendored Normal file
View File

@@ -0,0 +1,5 @@
declare module '*.vue' {
import { DefineComponent } from 'vue'
const component: DefineComponent<{}, {}, any>
export default component
}

10
src/views/home/index.vue Normal file
View File

@@ -0,0 +1,10 @@
<template>
<div>Home</div>
</template>
<script lang="ts" setup>
</script>
<style lang="scss" scoped>
</style>

1
src/vite-env.d.ts vendored Normal file
View File

@@ -0,0 +1 @@
/// <reference types="vite/client" />

14
tailwind.config.js Normal file
View File

@@ -0,0 +1,14 @@
module.exports = {
purge: [
'./index.html',
'./src/**/*.{vue,js,ts,jsx,tsx}'
],
darkMode: false, // or 'media' or 'class'
theme: {
extend: {},
},
variants: {
extend: {},
},
plugins: [],
}

19
tsconfig.json Normal file
View File

@@ -0,0 +1,19 @@
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"moduleResolution": "node",
"strict": true,
"jsx": "preserve",
"sourceMap": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"lib": ["esnext", "dom"],
"baseUrl": "./",
"paths": {
"@": ["src"],
"@/*": ["src/*"],
}
},
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"]
}

13
vite.config.ts Normal file
View File

@@ -0,0 +1,13 @@
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import path from "path";
// https://vitejs.dev/config/
export default defineConfig({
plugins: [vue()],
resolve: {
alias: {
"@": path.resolve(__dirname, "src"),
},
},
});