|
| 1 | +<template> |
| 2 | + <div id="app"> |
| 3 | + <img ref="img" v-ref="img=>this.img=img" alt="Vue logo" src="./assets/logo.png"> |
| 4 | + <br/> |
| 5 | + <a-button @click="updateMsg">update</a-button> |
| 6 | + <br/> |
| 7 | + <HelloWorld :msg="msg" v-if="show" ref="helloWorld" v-ref="helloWorld=>this.helloWorld=helloWorld"/> |
| 8 | + <div> |
| 9 | + <a-button ref="button" v-ref="btn=>this.button=btn" @click="show = !show">{{ show ? 'hide' : 'show' }}</a-button> |
| 10 | + <transition @enter="onEnter"> |
| 11 | + <div class="sidebar" v-show="show"> |
| 12 | + <scrollbar ref="scrollbar" v-ref="(c)=>this.scrollbar=c"></scrollbar> |
| 13 | + </div> |
| 14 | + </transition> |
| 15 | + </div> |
| 16 | + <span v-for="n in 5" :key="n" ref="spanList" v-ref="vForRef">{{ n }} </span> |
| 17 | + <Functional ref="functional" v-ref="c=>this.functional=c"/> |
| 18 | + </div> |
| 19 | +</template> |
| 20 | + |
| 21 | +<script> |
| 22 | +const Scrollbar = { |
| 23 | + methods: { |
| 24 | +updateScroll() { |
| 25 | +console.log('updateScroll called') |
| 26 | + } |
| 27 | + }, |
| 28 | + render(h) { |
| 29 | + return h('div', { |
| 30 | + class: 'scrollbar' |
| 31 | + }) |
| 32 | + } |
| 33 | +} |
| 34 | +import HelloWorld from './components/HelloWorld.vue' |
| 35 | +import Functional from './components/Functional.vue' |
| 36 | +export default { |
| 37 | + name: 'app', |
| 38 | + components: { |
| 39 | + HelloWorld, |
| 40 | + Scrollbar, |
| 41 | + Functional |
| 42 | + }, |
| 43 | + data() { |
| 44 | + return { |
| 45 | + show: false, |
| 46 | + msg: Date.now() |
| 47 | + } |
| 48 | + }, |
| 49 | + mounted() { |
| 50 | + console.log(this.$refs.spanList) |
| 51 | + console.log(this.img === this.$refs.img) |
| 52 | + console.log(this.helloWorld === this.$refs.helloWorld) |
| 53 | + console.log(this.button === this.$refs.button) |
| 54 | + console.log(this.scrollbar === this.$refs.scrollbar) |
| 55 | + console.log(this.functional === this.$refs.functional, this.$refs.functional, this.functional) |
| 56 | + }, |
| 57 | + updated() { |
| 58 | + console.log(this.img === this.$refs.img) |
| 59 | + console.log(this.helloWorld === this.$refs.helloWorld) |
| 60 | + console.log(this.button === this.$refs.button) |
| 61 | + console.log(this.scrollbar === this.$refs.scrollbar) |
| 62 | + console.log(this.functional === this.$refs.functional) |
| 63 | + }, |
| 64 | + methods: { |
| 65 | + onEnter() { |
| 66 | + this.scrollbar.updateScroll() |
| 67 | + }, |
| 68 | + vForRef(c, key){ |
| 69 | + console.log(c, key) |
| 70 | + }, |
| 71 | + updateMsg(){ |
| 72 | + this.msg = Date.now() |
| 73 | + } |
| 74 | + } |
| 75 | +} |
| 76 | +</script> |
| 77 | + |
| 78 | +<style> |
| 79 | +#app { |
| 80 | + font-family: 'Avenir', Helvetica, Arial, sans-serif; |
| 81 | + -webkit-font-smoothing: antialiased; |
| 82 | + -moz-osx-font-smoothing: grayscale; |
| 83 | + text-align: center; |
| 84 | + color: #2c3e50; |
| 85 | + margin-top: 60px; |
| 86 | +} |
| 87 | +.sidebar { |
| 88 | + position: fixed; |
| 89 | + top: 0; right: 0; bottom: 0; |
| 90 | + width: 200px; |
| 91 | + background: #000; |
| 92 | +} |
| 93 | +.sidebar.v-enter-active, |
| 94 | +.sidebar.v-leave-active { |
| 95 | + transition: transform .2s; |
| 96 | +} |
| 97 | +
|
| 98 | +.sidebar.v-enter, |
| 99 | +.sidebar.v-leave-active { |
| 100 | + transform: translate3d(100%, 0, 0); |
| 101 | +} |
| 102 | +</style> |
0 commit comments