App.vue 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836
  1. <script vapor>
  2. import {
  3. createComponent,
  4. defineVaporComponent,
  5. ref,
  6. shallowRef,
  7. VaporTransition,
  8. createIf,
  9. template,
  10. defineVaporAsyncComponent,
  11. onUnmounted,
  12. onUpdated,
  13. setElementText,
  14. renderEffect,
  15. inject,
  16. provide,
  17. child,
  18. txt,
  19. applyVShow,
  20. setText,
  21. delegateEvents,
  22. toDisplayString,
  23. } from 'vue'
  24. import VaporCompA from './components/VaporCompA.vue'
  25. import VaporCompB from './components/VaporCompB.vue'
  26. import VDomComp from './components/VdomComp.vue'
  27. const show = ref(true)
  28. const toggle = ref(true)
  29. const count = ref(0)
  30. const timeout = (fn, time) => setTimeout(fn, time)
  31. const duration = window.__TRANSITION_DURATION__ || 50
  32. let calls = {
  33. basic: [],
  34. withoutAppear: [],
  35. withArgs: [],
  36. enterCancel: [],
  37. withAppear: [],
  38. cssFalse: [],
  39. ifInOut: [],
  40. show: [],
  41. showLeaveCancel: [],
  42. showAppear: [],
  43. notEnter: [],
  44. updated: [],
  45. unmount: [],
  46. }
  47. window.getCalls = key => calls[key]
  48. window.resetCalls = key => (calls[key] = [])
  49. const activeComponent = shallowRef(VaporCompB)
  50. function toggleComponent() {
  51. activeComponent.value =
  52. activeComponent.value === VaporCompA ? VaporCompB : VaporCompA
  53. }
  54. const toggleVdom = ref(true)
  55. const interopComponent = shallowRef(VDomComp)
  56. function toggleInteropComponent() {
  57. interopComponent.value =
  58. interopComponent.value === VaporCompA ? VDomComp : VaporCompA
  59. }
  60. const name = ref('test')
  61. const MyTransition = defineVaporComponent((props, { slots }) => {
  62. return createComponent(VaporTransition, { name: () => 'test' }, slots)
  63. })
  64. const MyTransitionFallthroughAttr = defineVaporComponent((props, { slots }) => {
  65. return createComponent(
  66. VaporTransition,
  67. { foo: () => 1, name: () => 'test' },
  68. slots,
  69. )
  70. })
  71. const One = defineVaporComponent({
  72. setup() {
  73. return createIf(
  74. () => false,
  75. () => template('<div>one</div>', true)(),
  76. )
  77. },
  78. })
  79. const Two = defineVaporComponent({
  80. setup() {
  81. return template('<div>two</div>', true)()
  82. },
  83. })
  84. const view = shallowRef(One)
  85. function changeView() {
  86. view.value = view.value === One ? Two : One
  87. }
  88. const SimpleOne = defineVaporComponent({
  89. setup() {
  90. return template('<div>one</div>', true)()
  91. },
  92. })
  93. const viewInOut = shallowRef(SimpleOne)
  94. function changeViewInOut() {
  95. viewInOut.value = viewInOut.value === SimpleOne ? Two : SimpleOne
  96. }
  97. const AsyncComp = defineVaporAsyncComponent(() => {
  98. return new Promise(resolve => setTimeout(() => resolve(VaporCompA), 50))
  99. })
  100. const AsyncCompResolved = defineVaporAsyncComponent(() =>
  101. Promise.resolve(VaporCompA),
  102. )
  103. const TrueBranch = defineVaporComponent({
  104. name: 'TrueBranch',
  105. setup() {
  106. onUnmounted(() => {
  107. calls.unmount.push('TrueBranch')
  108. })
  109. return template('<div>0</div>')()
  110. },
  111. })
  112. const includeRef = ref(['TrueBranch'])
  113. const click = () => {
  114. toggle.value = !toggle.value
  115. if (toggle.value) {
  116. includeRef.value = ['TrueBranch']
  117. } else {
  118. includeRef.value = []
  119. }
  120. }
  121. const UnmountBranch = defineVaporComponent({
  122. name: 'UnmountBranch',
  123. setup() {
  124. onUnmounted(() => {
  125. calls.unmount.push('UnmountBranch')
  126. })
  127. return template('<div>0</div>')()
  128. },
  129. })
  130. const keepAliveUnmountRef = ref(null)
  131. window.getKeepAliveUnmountStorageContainer = () =>
  132. keepAliveUnmountRef.value?.ctx?.getStorageContainer?.() ?? null
  133. const unmountIncludeRef = ref(['UnmountBranch'])
  134. const unmountToggle = ref(true)
  135. const unmountClick = () => {
  136. unmountToggle.value = !unmountToggle.value
  137. if (unmountToggle.value) {
  138. unmountIncludeRef.value = ['UnmountBranch']
  139. } else {
  140. unmountIncludeRef.value = []
  141. }
  142. }
  143. const CompA = defineVaporComponent({
  144. name: 'CompA',
  145. setup() {
  146. onUpdated(() => {
  147. calls.updated.push('CompA updated')
  148. })
  149. return template('<div>CompA</div>')()
  150. },
  151. })
  152. const CompB = defineVaporComponent({
  153. name: 'CompB',
  154. setup() {
  155. return template('<div>CompB</div>')()
  156. },
  157. })
  158. const CompC = defineVaporComponent({
  159. name: 'CompC',
  160. setup() {
  161. onUnmounted(() => {
  162. calls.unmount.push('CompC unmounted')
  163. })
  164. return template('<div>CompC</div>')()
  165. },
  166. })
  167. const includeToChange = ref(['CompA', 'CompB', 'CompC'])
  168. const currentView = shallowRef(CompA)
  169. const switchToB = () => (currentView.value = CompB)
  170. const switchToC = () => (currentView.value = CompC)
  171. const switchToA = () => {
  172. currentView.value = CompA
  173. includeToChange.value = ['CompA']
  174. }
  175. const CompA2 = defineVaporComponent({
  176. name: 'CompA2',
  177. setup() {
  178. const current = inject('currentView2')
  179. const n0 = template('<div></div>')()
  180. renderEffect(() => setElementText(n0, toDisplayString(current.value.name)))
  181. return n0
  182. },
  183. })
  184. const CompB2 = defineVaporComponent({
  185. name: 'CompB2',
  186. setup() {
  187. onUnmounted(() => {
  188. calls.unmount.push('CompB2 unmounted')
  189. })
  190. const current = inject('currentView2')
  191. const n0 = template('<div></div>')()
  192. renderEffect(() => setElementText(n0, toDisplayString(current.value.name)))
  193. return n0
  194. },
  195. })
  196. const includeRef2 = ref(['CompA2'])
  197. const currentView2 = shallowRef(CompA2)
  198. provide('currentView2', currentView2)
  199. const switchToB2 = () => {
  200. currentView2.value = CompB2
  201. includeRef2.value = ['CompA2', 'CompB2']
  202. }
  203. const switchToA2 = () => {
  204. currentView2.value = CompA2
  205. includeRef2.value = ['CompA2']
  206. }
  207. const show2 = ref(true)
  208. const state = ref(1)
  209. const Item = defineVaporComponent({
  210. name: 'Item',
  211. setup() {
  212. return createComponent(
  213. VaporTransition,
  214. { name: () => 'test', persisted: () => '' },
  215. {
  216. default: () => {
  217. const n1 = template('<div><h2> </h2></div>')()
  218. const n0 = child(n1)
  219. const x0 = txt(n0)
  220. applyVShow(n1, () => show2.value)
  221. renderEffect(() =>
  222. setText(
  223. x0,
  224. toDisplayString(
  225. show2.value ? 'I should show' : "I shouldn't show ",
  226. ),
  227. ),
  228. )
  229. return n1
  230. },
  231. },
  232. )
  233. },
  234. })
  235. const Comp1 = defineVaporComponent({
  236. name: 'Comp1',
  237. setup() {
  238. delegateEvents('click')
  239. const n0 = createComponent(Item)
  240. const n1 = template('<h2>This is page1</h2>')()
  241. const n2 = template('<button id="changeShowBtn"></button>')()
  242. n2.$evtclick = () => (show2.value = !show2.value)
  243. renderEffect(() => {
  244. setElementText(n2, show2.value)
  245. })
  246. return [n0, n1, n2]
  247. },
  248. })
  249. const Comp2 = defineVaporComponent({
  250. name: 'Comp2',
  251. setup() {
  252. return template('<h2>This is page2</h2>')()
  253. },
  254. })
  255. </script>
  256. <template>
  257. <div class="transition-container">
  258. <!-- work with vif -->
  259. <div class="if-basic">
  260. <div>
  261. <transition>
  262. <div v-if="toggle" class="test">content</div>
  263. </transition>
  264. </div>
  265. <button @click="toggle = !toggle">basic toggle</button>
  266. </div>
  267. <div class="if-else-chain">
  268. <div>
  269. <transition>
  270. <div v-if="count === 0" class="test">0</div>
  271. <div v-else-if="count === 1" class="test">1</div>
  272. <div v-else class="test">2</div>
  273. </transition>
  274. </div>
  275. <button @click="count++">inc</button>
  276. </div>
  277. <div class="if-else-chain-out-in">
  278. <div>
  279. <transition mode="out-in">
  280. <div v-if="count === 0" class="test">0</div>
  281. <div v-else-if="count === 1" class="test">1</div>
  282. <div v-else class="test">2</div>
  283. </transition>
  284. </div>
  285. <button @click="count++">inc</button>
  286. </div>
  287. <div class="if-named">
  288. <div>
  289. <transition name="test">
  290. <div v-if="toggle" class="test">content</div>
  291. </transition>
  292. </div>
  293. <button @click="toggle = !toggle">button</button>
  294. </div>
  295. <div class="if-custom-classes">
  296. <div>
  297. <transition
  298. enter-from-class="hello-from"
  299. enter-active-class="hello-active"
  300. enter-to-class="hello-to"
  301. leave-from-class="bye-from"
  302. leave-active-class="bye-active"
  303. leave-to-class="bye-to"
  304. >
  305. <div v-if="toggle" class="test">content</div>
  306. </transition>
  307. </div>
  308. <button @click="toggle = !toggle">button</button>
  309. </div>
  310. <div class="if-dynamic-name">
  311. <div>
  312. <transition :name="name">
  313. <div v-if="toggle" class="test">content</div>
  314. </transition>
  315. </div>
  316. <button class="toggle" @click="toggle = !toggle">button</button>
  317. <button class="change" @click="name = 'changed'">{{ name }}</button>
  318. </div>
  319. <div class="if-events-without-appear">
  320. <div>
  321. <transition
  322. name="test"
  323. @before-enter="() => calls.withoutAppear.push('beforeEnter')"
  324. @enter="() => calls.withoutAppear.push('onEnter')"
  325. @after-enter="() => calls.withoutAppear.push('afterEnter')"
  326. @beforeLeave="() => calls.withoutAppear.push('beforeLeave')"
  327. @leave="() => calls.withoutAppear.push('onLeave')"
  328. @afterLeave="() => calls.withoutAppear.push('afterLeave')"
  329. >
  330. <div v-if="toggle" class="test">content</div>
  331. </transition>
  332. </div>
  333. <button @click="toggle = !toggle">button</button>
  334. </div>
  335. <div class="if-events-with-args">
  336. <div>
  337. <transition
  338. :css="false"
  339. name="test"
  340. @before-enter="
  341. el => {
  342. calls.withArgs.push('beforeEnter')
  343. el.classList.add('before-enter')
  344. }
  345. "
  346. @enter="
  347. (el, done) => {
  348. calls.withArgs.push('onEnter')
  349. el.classList.add('enter')
  350. timeout(done, 200)
  351. }
  352. "
  353. @after-enter="
  354. el => {
  355. calls.withArgs.push('afterEnter')
  356. el.classList.add('after-enter')
  357. }
  358. "
  359. @before-leave="
  360. el => {
  361. calls.withArgs.push('beforeLeave')
  362. el.classList.add('before-leave')
  363. }
  364. "
  365. @leave="
  366. (el, done) => {
  367. calls.withArgs.push('onLeave')
  368. el.classList.add('leave')
  369. timeout(done, 200)
  370. }
  371. "
  372. @after-leave="
  373. () => {
  374. calls.withArgs.push('afterLeave')
  375. }
  376. "
  377. >
  378. <div v-if="toggle" class="test">content</div>
  379. </transition>
  380. </div>
  381. <button @click="toggle = !toggle">button</button>
  382. </div>
  383. <div class="if-enter-cancelled">
  384. <div>
  385. <transition
  386. name="test"
  387. @enter-cancelled="
  388. () => {
  389. calls.enterCancel.push('enterCancelled')
  390. }
  391. "
  392. >
  393. <div v-if="!toggle" class="test">content</div>
  394. </transition>
  395. </div>
  396. <button @click="toggle = !toggle">cancelled</button>
  397. </div>
  398. <div class="if-appear">
  399. <div>
  400. <transition
  401. name="test"
  402. appear
  403. appear-from-class="test-appear-from"
  404. appear-to-class="test-appear-to"
  405. appear-active-class="test-appear-active"
  406. >
  407. <div v-if="toggle" class="test">content</div>
  408. </transition>
  409. </div>
  410. <button @click="toggle = !toggle">button</button>
  411. </div>
  412. <div class="if-events-with-appear">
  413. <div>
  414. <transition
  415. name="test"
  416. appear
  417. appear-from-class="test-appear-from"
  418. appear-to-class="test-appear-to"
  419. appear-active-class="test-appear-active"
  420. @beforeEnter="() => calls.withAppear.push('beforeEnter')"
  421. @enter="() => calls.withAppear.push('onEnter')"
  422. @afterEnter="() => calls.withAppear.push('afterEnter')"
  423. @beforeLeave="() => calls.withAppear.push('beforeLeave')"
  424. @leave="() => calls.withAppear.push('onLeave')"
  425. @afterLeave="() => calls.withAppear.push('afterLeave')"
  426. @beforeAppear="() => calls.withAppear.push('beforeAppear')"
  427. @appear="() => calls.withAppear.push('onAppear')"
  428. @afterAppear="() => calls.withAppear.push('afterAppear')"
  429. >
  430. <div v-if="toggle" class="test">content</div>
  431. </transition>
  432. </div>
  433. <button @click="toggle = !toggle">button</button>
  434. </div>
  435. <div class="if-css-false">
  436. <div>
  437. <transition
  438. :css="false"
  439. name="test"
  440. @beforeEnter="() => calls.cssFalse.push('beforeEnter')"
  441. @enter="() => calls.cssFalse.push('onEnter')"
  442. @afterEnter="() => calls.cssFalse.push('afterEnter')"
  443. @beforeLeave="() => calls.cssFalse.push('beforeLeave')"
  444. @leave="() => calls.cssFalse.push('onLeave')"
  445. @afterLeave="() => calls.cssFalse.push('afterLeave')"
  446. >
  447. <div v-if="toggle" class="test">content</div>
  448. </transition>
  449. </div>
  450. <button @click="toggle = !toggle"></button>
  451. </div>
  452. <div class="if-no-trans">
  453. <div>
  454. <transition name="noop">
  455. <div v-if="toggle">content</div>
  456. </transition>
  457. </div>
  458. <button @click="toggle = !toggle">button</button>
  459. </div>
  460. <div class="if-ani">
  461. <div>
  462. <transition name="test-anim">
  463. <div v-if="toggle">content</div>
  464. </transition>
  465. </div>
  466. <button @click="toggle = !toggle">button</button>
  467. </div>
  468. <div class="if-ani-explicit-type">
  469. <div>
  470. <transition name="test-anim-long" type="animation">
  471. <div v-if="toggle">content</div>
  472. </transition>
  473. </div>
  474. <button @click="toggle = !toggle">button</button>
  475. </div>
  476. <div class="if-high-order">
  477. <div>
  478. <MyTransition>
  479. <div v-if="toggle" class="test">content</div>
  480. </MyTransition>
  481. </div>
  482. <button @click="toggle = !toggle">button</button>
  483. </div>
  484. <div class="if-empty-root">
  485. <div>
  486. <transition name="test">
  487. <component class="test" :is="view"></component>
  488. </transition>
  489. </div>
  490. <button class="toggle" @click="toggle = !toggle">button</button>
  491. <button class="change" @click="changeView">changeView button</button>
  492. </div>
  493. <div class="if-at-component-root-level">
  494. <div>
  495. <transition name="test" mode="out-in">
  496. <component class="test" :is="view"></component>
  497. </transition>
  498. </div>
  499. <button class="toggle" @click="toggle = !toggle">button</button>
  500. <button class="change" @click="changeView">changeView button</button>
  501. </div>
  502. <div class="if-fallthrough-attr">
  503. <div>
  504. <MyTransitionFallthroughAttr>
  505. <div v-if="toggle">content</div>
  506. </MyTransitionFallthroughAttr>
  507. </div>
  508. <button @click="toggle = !toggle">button fallthrough</button>
  509. </div>
  510. <div class="if-fallthrough-attr-in-out">
  511. <div>
  512. <transition
  513. foo="1"
  514. name="test"
  515. mode="in-out"
  516. @beforeEnter="() => calls.ifInOut.push('beforeEnter')"
  517. @enter="() => calls.ifInOut.push('onEnter')"
  518. @afterEnter="() => calls.ifInOut.push('afterEnter')"
  519. @beforeLeave="() => calls.ifInOut.push('beforeLeave')"
  520. @leave="() => calls.ifInOut.push('onLeave')"
  521. @afterLeave="() => calls.ifInOut.push('afterLeave')"
  522. >
  523. <component :is="viewInOut"></component>
  524. </transition>
  525. </div>
  526. <button @click="changeViewInOut">button</button>
  527. </div>
  528. <!-- work with vif end -->
  529. <!-- work with vshow -->
  530. <div class="show-named">
  531. <div>
  532. <transition name="test">
  533. <div v-show="toggle" class="test">content</div>
  534. </transition>
  535. </div>
  536. <button @click="toggle = !toggle">button</button>
  537. </div>
  538. <div class="show-events">
  539. <div>
  540. <transition
  541. name="test"
  542. @beforeEnter="() => calls.show.push('beforeEnter')"
  543. @enter="() => calls.show.push('onEnter')"
  544. @afterEnter="() => calls.show.push('afterEnter')"
  545. @beforeLeave="() => calls.show.push('beforeLeave')"
  546. @leave="() => calls.show.push('onLeave')"
  547. @afterLeave="() => calls.show.push('afterLeave')"
  548. >
  549. <div v-show="toggle" class="test">content</div>
  550. </transition>
  551. </div>
  552. <button @click="toggle = !toggle">button</button>
  553. </div>
  554. <div class="show-leave-cancelled">
  555. <div>
  556. <transition
  557. name="test"
  558. @leave-cancelled="() => calls.showLeaveCancel.push('leaveCancelled')"
  559. >
  560. <div v-show="toggle" class="test">content</div>
  561. </transition>
  562. </div>
  563. <button @click="toggle = !toggle">leave cancelled</button>
  564. </div>
  565. <div class="show-appear">
  566. <div>
  567. <transition
  568. name="test"
  569. appear
  570. appear-from-class="test-appear-from"
  571. appear-to-class="test-appear-to"
  572. appear-active-class="test-appear-active"
  573. @beforeEnter="() => calls.showAppear.push('beforeEnter')"
  574. @enter="() => calls.showAppear.push('onEnter')"
  575. @afterEnter="() => calls.showAppear.push('afterEnter')"
  576. >
  577. <div v-show="toggle" class="test">content</div>
  578. </transition>
  579. </div>
  580. <button @click="toggle = !toggle">button</button>
  581. </div>
  582. <div class="show-appear-not-enter">
  583. <div>
  584. <transition
  585. name="test"
  586. appear
  587. @beforeEnter="() => calls.notEnter.push('beforeEnter')"
  588. @enter="() => calls.notEnter.push('onEnter')"
  589. @afterEnter="() => calls.notEnter.push('afterEnter')"
  590. >
  591. <div v-show="!toggle" class="test">content</div>
  592. </transition>
  593. </div>
  594. <button @click="toggle = !toggle">button</button>
  595. </div>
  596. <!-- work with vshow end -->
  597. <!-- explicit durations -->
  598. <div class="duration-single-value">
  599. <div>
  600. <transition name="test" :duration="duration * 2">
  601. <div v-if="toggle" class="test">content</div>
  602. </transition>
  603. </div>
  604. <button @click="toggle = !toggle">button</button>
  605. </div>
  606. <div class="duration-enter">
  607. <div>
  608. <transition name="test" :duration="{ enter: duration * 2 }">
  609. <div v-if="toggle" class="test">content</div>
  610. </transition>
  611. </div>
  612. <button @click="toggle = !toggle">button</button>
  613. </div>
  614. <div class="duration-leave">
  615. <div>
  616. <transition name="test" :duration="{ leave: duration * 2 }">
  617. <div v-if="toggle" class="test">content</div>
  618. </transition>
  619. </div>
  620. <button @click="toggle = !toggle">button</button>
  621. </div>
  622. <div class="duration-enter-leave">
  623. <div>
  624. <transition
  625. name="test"
  626. :duration="{ enter: duration * 4, leave: duration * 2 }"
  627. >
  628. <div v-if="toggle" class="test">content</div>
  629. </transition>
  630. </div>
  631. <button @click="toggle = !toggle">button</button>
  632. </div>
  633. <!-- explicit durations end -->
  634. <!-- keyed fragment -->
  635. <div class="keyed">
  636. <button @click="count++">inc</button>
  637. <Transition>
  638. <h1 style="position: absolute" :key="count">{{ count }}</h1>
  639. </Transition>
  640. </div>
  641. <!-- keyed fragment end -->
  642. <!-- mode -->
  643. <div class="out-in">
  644. <button @click="toggleComponent">toggle out-in</button>
  645. <div>
  646. <Transition name="fade" mode="out-in">
  647. <component :is="activeComponent"></component>
  648. </Transition>
  649. </div>
  650. </div>
  651. <div class="in-out">
  652. <button @click="toggleComponent">toggle in-out</button>
  653. <div>
  654. <Transition name="fade" mode="in-out">
  655. <component :is="activeComponent"></component>
  656. </Transition>
  657. </div>
  658. </div>
  659. <!-- mode end -->
  660. <!-- async component -->
  661. <div class="async">
  662. <div id="container">
  663. <transition>
  664. <AsyncComp v-if="!toggle"></AsyncComp>
  665. </transition>
  666. </div>
  667. <button @click="toggle = !toggle">button</button>
  668. </div>
  669. <div class="async-resolved">
  670. <!-- Pre-resolve the async component by rendering it hidden -->
  671. <div id="hidden-async">
  672. <AsyncCompResolved v-show="false" />
  673. </div>
  674. <div id="container">
  675. <transition>
  676. <AsyncCompResolved v-if="!toggle"></AsyncCompResolved>
  677. </transition>
  678. </div>
  679. <button @click="toggle = !toggle">button</button>
  680. </div>
  681. <!-- async component end -->
  682. <!-- with teleport -->
  683. <div class="with-teleport">
  684. <div class="target"></div>
  685. <div class="container">
  686. <Transition>
  687. <Teleport to=".target" defer>
  688. <!-- comment -->
  689. <VaporCompB v-if="!toggle" class="test"></VaporCompB>
  690. </Teleport>
  691. </Transition>
  692. </div>
  693. <button @click="toggle = !toggle">button</button>
  694. </div>
  695. <!-- with teleport end -->
  696. <!-- with keep-alive -->
  697. <div class="keep-alive">
  698. <div>
  699. <transition mode="out-in">
  700. <KeepAlive :include="includeRef">
  701. <TrueBranch v-if="toggle"></TrueBranch>
  702. </KeepAlive>
  703. </transition>
  704. </div>
  705. <button @click="click">button</button>
  706. </div>
  707. <div class="keep-alive-unmount-children">
  708. <div id="container">
  709. <transition>
  710. <KeepAlive ref="keepAliveUnmountRef" :include="unmountIncludeRef">
  711. <UnmountBranch v-if="unmountToggle"></UnmountBranch>
  712. </KeepAlive>
  713. </transition>
  714. </div>
  715. <button id="toggleBtn" @click="unmountClick">button</button>
  716. </div>
  717. <div class="keep-alive-update-include">
  718. <div>
  719. <transition mode="out-in">
  720. <KeepAlive :include="includeToChange">
  721. <component :is="currentView" />
  722. </KeepAlive>
  723. </transition>
  724. </div>
  725. <button id="switchToB" @click="switchToB">switchToB</button>
  726. <button id="switchToC" @click="switchToC">switchToC</button>
  727. <button id="switchToA" @click="switchToA">switchToA</button>
  728. </div>
  729. <div class="keep-alive-switch-then-update-include">
  730. <div>
  731. <transition name="test-anim" mode="out-in">
  732. <KeepAlive :include="includeRef2">
  733. <component :is="currentView2" />
  734. </KeepAlive>
  735. </transition>
  736. </div>
  737. <button id="switchToA" @click="switchToA2">switchToA</button>
  738. <button id="switchToB" @click="switchToB2">switchToB</button>
  739. </div>
  740. <div class="keep-alive-move-before-leave-finishes">
  741. <div>
  742. <KeepAlive :include="['Comp1', 'Comp2']">
  743. <component :is="state === 1 ? Comp1 : Comp2" />
  744. </KeepAlive>
  745. </div>
  746. <button @click="state = state === 1 ? 2 : 1">button</button>
  747. </div>
  748. <!-- with keep-alive end -->
  749. <!-- with svg -->
  750. <div class="svg">
  751. <svg id="container">
  752. <transition name="test">
  753. <circle v-if="toggle" cx="0" cy="0" r="10" class="test"></circle>
  754. </transition>
  755. </svg>
  756. <button id="toggleBtn" @click="toggle = !toggle">button</button>
  757. </div>
  758. <!-- with svg end -->
  759. <!-- vdom interop -->
  760. <div class="vdom">
  761. <button @click="toggleVdom = !toggleVdom">toggle vdom component</button>
  762. <div>
  763. <Transition>
  764. <VDomComp v-if="toggleVdom" />
  765. </Transition>
  766. </div>
  767. </div>
  768. <div class="vdom-vapor-out-in">
  769. <button @click="toggleInteropComponent">
  770. switch between vdom/vapor component out-in mode
  771. </button>
  772. <div>
  773. <Transition name="fade" mode="out-in">
  774. <component :is="interopComponent"></component>
  775. </Transition>
  776. </div>
  777. </div>
  778. <div class="vdom-vapor-in-out">
  779. <button @click="toggleVdom = !toggleVdom">
  780. switch between vdom/vapor component in-out mode
  781. </button>
  782. <div>
  783. <Transition name="fade" mode="in-out">
  784. <VaporCompA v-if="toggleVdom" />
  785. <VDomComp v-else></VDomComp>
  786. </Transition>
  787. </div>
  788. </div>
  789. <!-- vdom interop end -->
  790. </div>
  791. </template>
  792. <style>
  793. .keyed {
  794. height: 100px;
  795. }
  796. </style>
  797. <style>
  798. .transition-container > div {
  799. padding: 15px;
  800. border: 1px solid #f7f7f7;
  801. margin-top: 15px;
  802. }
  803. </style>