Skip to content

Commit 52454a0

Browse files
committed
practical examples
1 parent 401301b commit 52454a0

File tree

17 files changed

+240
-19
lines changed

17 files changed

+240
-19
lines changed

src/.vitepress/config.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ const sidebar = {
407407
},
408408
{
409409
text: 'List with Transitions',
410-
link: '/examples/#list'
410+
link: '/examples/#list-transition'
411411
},
412412
{
413413
text: 'TodoMVC',
@@ -480,12 +480,12 @@ module.exports = {
480480
optimizeDeps: {
481481
exclude: ['@vue/repl']
482482
},
483-
server: {
484-
host: true
485-
},
486483
ssr: {
487484
external: ['@vue/repl']
488485
},
486+
server: {
487+
host: true
488+
},
489489
build: {
490490
chunkSizeWarningLimit: Infinity
491491
},

src/examples/ExampleRepl.vue

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { Repl, ReplStore } from '@vue/repl'
33
import '@vue/repl/style.css'
44
import data from './data.json'
5-
import { inject, watchEffect, version, Ref } from 'vue'
5+
import { computed, inject, watchEffect, version, Ref } from 'vue'
66
77
const store = new ReplStore({
88
defaultVueRuntimeURL: `https://unpkg.com/vue@${version}/dist/vue.esm-browser.js`
@@ -196,7 +196,12 @@ function toKebabTags(str: string): string {
196196
</script>
197197

198198
<template>
199-
<Repl :store="store" :showCompileOutput="false" :clearConsole="false" />
199+
<Repl
200+
:store="store"
201+
:showImportMap="!preferSFC"
202+
:showCompileOutput="false"
203+
:clearConsole="false"
204+
/>
200205
</template>
201206

202207
<style scoped>

src/examples/src/attribute-bindings/App/composition.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default {
1616

1717
return {
1818
message,
19-
isRef,
19+
isRed,
2020
color,
2121
toggleRed,
2222
toggleColor
Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,38 @@
1+
import { shuffle as _shuffle } from 'lodash-es'
2+
import { ref } from 'vue'
3+
14
export default {
25
setup() {
3-
const message = 'Hello World!'
6+
const getInitialItems = () => [1, 2, 3, 4, 5]
7+
const items = ref(getInitialItems())
8+
let id = items.value.length + 1
9+
10+
function insert() {
11+
const i = Math.round(Math.random() * items.value.length)
12+
items.value.splice(i, 0, id++)
13+
}
14+
15+
function reset() {
16+
items.value = getInitialItems()
17+
}
18+
19+
function shuffle() {
20+
items.value = _shuffle(items.value)
21+
}
22+
23+
function remove(item) {
24+
const i = items.value.indexOf(item)
25+
if (i > -1) {
26+
items.value.splice(i, 1)
27+
}
28+
}
429

530
return {
6-
message
31+
items,
32+
insert,
33+
reset,
34+
shuffle,
35+
remove
736
}
837
}
938
}
Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,30 @@
1+
import { shuffle } from 'lodash-es'
2+
3+
const getInitialItems = () => [1, 2, 3, 4, 5]
4+
let id = getInitialItems().length + 1
5+
16
export default {
27
data() {
38
return {
4-
message: 'Hello World!'
9+
items: getInitialItems()
10+
}
11+
},
12+
methods: {
13+
insert() {
14+
const i = Math.round(Math.random() * this.items.length)
15+
this.items.splice(i, 0, id++)
16+
},
17+
reset() {
18+
this.items = getInitialItems()
19+
},
20+
shuffle() {
21+
this.items = shuffle(this.items)
22+
},
23+
remove(item) {
24+
const i = this.items.indexOf(item)
25+
if (i > -1) {
26+
this.items.splice(i, 1)
27+
}
528
}
629
}
7-
}
30+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
.container {
2+
position: relative;
3+
padding: 0;
4+
}
5+
6+
.item {
7+
width: 100%;
8+
height: 30px;
9+
background-color: #f3f3f3;
10+
border: 1px solid #666;
11+
box-sizing: border-box;
12+
}
13+
14+
/* 1. declare transition */
15+
.fade-move,
16+
.fade-enter-active,
17+
.fade-leave-active {
18+
transition: all 0.5s cubic-bezier(0.55, 0, 0.1, 1);
19+
}
20+
21+
/* 2. declare enter from and leave to state */
22+
.fade-enter-from,
23+
.fade-leave-to {
24+
opacity: 0;
25+
transform: scaleY(0.01) translate(30px, 0);
26+
}
27+
28+
/* 3. ensure leaving items are taken out of layout flow so that moving
29+
animations can be calculated correctly. */
30+
.fade-leave-active {
31+
position: absolute;
32+
}
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
1-
<h1>{{ message }}</h1>
1+
<button @click="insert">insert at random index</button>
2+
<button @click="reset">reset</button>
3+
<button @click="shuffle">shuffle</button>
4+
5+
<TransitionGroup tag="ul" name="fade" class="container">
6+
<div v-for="item in items" class="item" :key="item">
7+
{{ item }}
8+
<button @click="remove(item)">x</button>
9+
</div>
10+
</TransitionGroup>
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
Say Hello World with Vue!
1+
FLIP list transitions with the built-in <TransitionGroup>.
2+
https://aerotwist.com/blog/flip-your-animations/
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"imports": {
3+
"lodash-es": "https://cdn.jsdelivr.net/npm/lodash-es/+esm"
4+
}
5+
}
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1+
import Modal from './Modal.vue'
2+
import { ref } from 'vue'
3+
14
export default {
5+
components: {
6+
Modal
7+
},
28
setup() {
3-
const message = 'Hello World!'
9+
const showModal = ref(false)
410

511
return {
6-
message
12+
showModal
713
}
814
}
915
}

0 commit comments

Comments
 (0)