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
Changes from 1 commit
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
Prev Previous commit
feat: 🚀 allows passing in custom component ref,
17359898647 committed Sep 6, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 3bddf4869bc3cc1288e770b9df63401f737a3854
16 changes: 16 additions & 0 deletions src/vue/example/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
<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>

1 change: 1 addition & 0 deletions src/vue/example/src/component/Original.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<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({
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>