App.vue 22 KB

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