Skip to content

Commit

Permalink
chore: 更新readme
Browse files Browse the repository at this point in the history
  • Loading branch information
hooray committed Sep 12, 2024
1 parent 8e5aa27 commit fc3617b
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 3 deletions.
77 changes: 77 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# vite-plugin-vue-app-loading

[![NPM version](https://img.shields.io/npm/v/vite-plugin-vue-app-loading?color=a1b858&label=)](https://www.npmjs.com/package/vite-plugin-vue-app-loading)

给 Vue 应用添加一个加载动画。

## 安装

```bash
npm i vite-plugin-vue-app-loading -D
```

## 使用

```ts
// vite.config.ts
import AppLoading from 'vite-plugin-vue-app-loading'

export default defineConfig({
plugins: [
AppLoading(),
],
})
```

```ts
// src/main.ts
import { loadingFadeOut } from 'virtual:app-loading'
loadingFadeOut()
```

## TypeScript

```json
// tsconfig.json
{
"compilerOptions": {
"types": [
"vite-plugin-vue-app-loading/client"
]
}
}
```

## 自定义动画

在应用根目录创建 `loading.html` 文件,例如:

```html
<style>
.loader {
font-weight: bold;
font-family: sans-serif;
font-size: 30px;
animation: l1 1s linear infinite alternate;
}
.loader:before {
content:"Loading..."
}
@keyframes l1 {to{opacity: 0}}
</style>
<div class="loader"></div>
```

```ts
// vite.config.ts
import AppLoading from 'vite-plugin-vue-app-loading'

export default defineConfig({
plugins: [
AppLoading('loading.html'),
],
})
```

> [!TIP]
> 你可以从 [CSS Loaders](https://css-loaders.com/) 网站中找找灵感,它提供了 600+ 个纯 CSS 的加载动画。
7 changes: 4 additions & 3 deletions example/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { loadingFadeOut } from 'virtual:app-loading'
import { createApp } from 'vue'
import './style.css'
import App from './App.vue'

import './style.css'

createApp(App).mount('#app')

import { loadingFadeOut } from 'virtual:app-loading'
loadingFadeOut()
loadingFadeOut()

0 comments on commit fc3617b

Please sign in to comment.