Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vue版本useAutoAnimate允许传入el,兼容旧版 #159

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/vue/example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
18 changes: 18 additions & 0 deletions src/vue/example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Vue 3 + TypeScript + Vite

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.

## Recommended IDE Setup

- [VS Code](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur) + [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin).

## Type Support For `.vue` Imports in TS

TypeScript cannot handle type information for `.vue` imports by default, so we replace the `tsc` CLI with `vue-tsc` for type checking. In editors, we need [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin) to make the TypeScript language service aware of `.vue` types.

If the standalone TypeScript plugin doesn't feel fast enough to you, Volar has also implemented a [Take Over Mode](https://github.com/johnsoncodehk/volar/discussions/471#discussioncomment-1361669) that is more performant. You can enable it by the following steps:

1. Disable the built-in TypeScript Extension
1. Run `Extensions: Show Built-in Extensions` from VSCode's command palette
2. Find `TypeScript and JavaScript Language Features`, right click and select `Disable (Workspace)`
2. Reload the VSCode window by running `Developer: Reload Window` from the command palette.
13 changes: 13 additions & 0 deletions src/vue/example/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + Vue + TS</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
20 changes: 20 additions & 0 deletions src/vue/example/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "example",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vue-tsc && vite build",
"preview": "vite preview"
},
"dependencies": {
"vue": "^3.3.4"
},
"devDependencies": {
"@vitejs/plugin-vue": "^4.2.3",
"typescript": "^5.0.2",
"vite": "^4.4.5",
"vue-tsc": "^1.8.5"
}
}
34 changes: 34 additions & 0 deletions src/vue/example/src/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<script setup lang="ts">
import Original from "./component/Original.vue"
import NewCode from "./component/newCode.vue"
import { useAutoAnimate } from "../../index.ts"
import { onMounted, ref } from "vue"
import VueCom from "./component/VueCom.vue"
const defaultList=()=>[1,2,3,4,5,6,7,8,9,10]
const list=ref(defaultList())
const [containerRef,setEnabled]=useAutoAnimate({
duration:500
})
const randomSort=()=>{
list.value.sort(()=>Math.random()-0.5)
}
const reset=()=>{
list.value=defaultList()
console.log(list.value)
}
</script>

<template>
<div class="container">
<Original/>
<NewCode/>
<VueCom/>
</div>
</template>

<style scoped>
.container{
display: flex;
gap: 10px;
}
</style>
51 changes: 51 additions & 0 deletions src/vue/example/src/component/Original.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<script setup lang="ts">
import { useAutoAnimate } from "../../../index.ts"
import { onMounted, ref } from "vue"

const defaultList=()=>[1,2,3,4,5,6,7,8,9,10]
const list=ref(defaultList())
const [containerRef,setEnabled]=useAutoAnimate({
duration:500
})
const randomSort=()=>{
list.value.sort(()=>Math.random()-0.5)
}
const reset=()=>{
list.value=defaultList()
console.log(list.value)
}
</script>

<template>
<div class="container column gap">
<h1>Original</h1>
<div>
<button @click="randomSort">sort</button>
<button @click="reset">rest</button>
<button @click="()=>setEnabled(true)">turn on</button>
<button @click="()=>setEnabled(false)">turn off</button>
</div>
<div ref="containerRef" >
<div v-for="item in list" class="box" :key="item">
{{ item }}
</div>
</div>
</div>
</template>

<style scoped>
.container{
display: flex;
}
.gap{
gap: 10px;
}
.column{
flex-direction: column;
}
.box{
width: 30px;
height: 30px;
background-color: red;
}
</style>
54 changes: 54 additions & 0 deletions src/vue/example/src/component/VueCom.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<script setup lang="ts">
import { useAutoAnimate } from "../../../index.ts"
import { onMounted, ref } from "vue"
import VueSlot from "./VueSlot.vue"

const defaultList=()=>[1,2,3,4,5,6,7,8,9,10]
const list=ref(defaultList())
const containerRef=ref()
const [_,setEnabled]=useAutoAnimate({
el:containerRef,
duration:500
})
const randomSort=()=>{
list.value.sort(()=>Math.random()-0.5)
}
const reset=()=>{
list.value=defaultList()
console.log(list.value)
}
</script>

<template>
<div class="container column gap">
<h1>VueCom</h1>
<div>
<button @click="randomSort">sort</button>
<button @click="reset">rest</button>
<button @click="()=>setEnabled(true)">turn on</button>
<button @click="()=>setEnabled(false)">turn off</button>
</div>
<VueSlot ref="containerRef" >
<div v-for="item in list" class="box" :key="item">
{{ item }}
</div>
</VueSlot>
</div>
</template>

<style scoped>
.container{
display: flex;
}
.gap{
gap: 10px;
}
.column{
flex-direction: column;
}
.box{
width: 30px;
height: 30px;
background-color: red;
}
</style>
23 changes: 23 additions & 0 deletions src/vue/example/src/component/VueSlot.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<template>
<div class="container column">
<slot/>
</div>
</template>

<style scoped>

.container{
display: flex;
}
.gap{
gap: 10px;
}
.column{
flex-direction: column;
}
.box{
width: 30px;
height: 30px;
background-color: red;
}
</style>
58 changes: 58 additions & 0 deletions src/vue/example/src/component/newCode.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<script setup lang="ts">
import { useAutoAnimate } from "../../../index.ts"
import { onMounted, ref } from "vue"
const defaultList=()=>[1,2,3,4,5,6,7,8,9,10]
const list=ref(defaultList())
const containerRef=ref<HTMLElement|null>(null)
const [_containerRef,setEnabled]=useAutoAnimate({
el:containerRef,
duration:1000,
})
onMounted(()=>{
console.log(containerRef === _containerRef)
})
const randomSort=()=>{
list.value.sort(()=>Math.random()-0.5)
}
const reset=()=>{
list.value=defaultList()
console.log(list.value)
}
</script>

<template>
<div class="container column gap">
<h1>newCode</h1>
<div>
<button @click="randomSort">sort</button>
<button @click="reset">rest</button>
<button @click="()=>setEnabled(true)">turn on</button>
<button @click="()=>setEnabled(false)">turn off</button>
</div>
<div ref="containerRef" >
<div v-for="item in list" class="box" :key="item">
{{ item }}
</div>
</div>
</div>
</template>

<style scoped>
.container{
display: flex;
}
.gap{
gap: 10px;
}
.column{
flex-direction: column;
}
.box{
width: 30px;
height: 30px;
background-color: red;
display: flex;
align-items: center;
justify-content: center;
}
</style>
5 changes: 5 additions & 0 deletions src/vue/example/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// @ts-ignore
import { createApp } from 'vue'
import App from './App.vue'

createApp(App).mount('#app')
1 change: 1 addition & 0 deletions src/vue/example/src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
25 changes: 25 additions & 0 deletions src/vue/example/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"skipLibCheck": true,

/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve",

/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
"references": [{ "path": "./tsconfig.node.json" }]
}
10 changes: 10 additions & 0 deletions src/vue/example/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"composite": true,
"skipLibCheck": true,
"module": "ESNext",
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true
},
"include": ["vite.config.ts"]
}
7 changes: 7 additions & 0 deletions src/vue/example/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

// https://vitejs.dev/config/
export default defineConfig({
plugins: [vue()],
})
Loading