1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
| <template> <div style="background-color: #6495ed"> <header>我是子组件</header> <span>{{year}}</span> <button @click="changeTime">时光机</button> <br/> <button @click="destroy">点我销毁子组件</button> </div> </template>
<script> export default { name: "child", data() { return { year: '现在是2020年' } }, props: ['proptest'], methods: { changeTime() { this.year === '大人,时代变了' ? this.year = '现在是2020年' : this.year = '大人,时代变了' }, methodsAvailable() {
}, destroy(){ this.$destroy() } }, computed: { time() { return Date.now() } }, beforeCreate() { console.log('------------start-------------') console.log('当前是beforeCreate') console.log('this', this) console.log('el', this.$el) console.log('data', this.$data) console.log('prop', this.$props) console.log('watch', this._watchers) console.log('methods', this.methodsAvailable) console.log('computed', this.time) console.log('year', this.year) console.log('------------end-------------') console.log('') }, created() { console.log('------------start-------------') console.log('当前是created') console.log('el', this.$el) console.log('data', this.$data) console.log('prop', this.$props) console.log('watch', this._watchers) console.log('methods', this.methodsAvailable) console.log('computed', this.time) console.log('year', this.year) console.log('------------end-------------') console.log('') }, beforeMount() { console.log('------------start-------------') console.log('当前是beforeMount') console.log('el', this.$el) console.log('data', this.$data) console.log('year', this.year) console.log('------------end-------------') console.log('') }, mounted() { console.log('------------start-------------') console.log('当前是mounted') console.log('el', this.$el) console.log('data', this.$data) console.log('year', this.year) console.log('------------end-------------') console.log('')
}, beforeUpdate() { console.log('------------start-------------') console.log('当前是beforeUpdate') console.log('el', this.$el.innerHTML) console.log('data', JSON.stringify(this.$data)) console.log('year', this.year) console.log('------------end-------------') console.log('') }, updated() { console.log('------------start-------------') console.log('当前是updated') console.log('el', this.$el.innerHTML) console.log('data', JSON.stringify(this.$data)) console.log('year', this.year) console.log('------------end-------------') console.log('') }, beforeDestroy() { console.log('------------start-------------') console.log('当前是beforeDestroy') console.log('el', this.$el) console.log('data', this.$data) console.log('year', this.year) console.log('------------end-------------') console.log('') }, destroyed() { console.log('------------start-------------') console.log('当前是destroyed') console.log('el', this.$el) console.log('data', this.$data) console.log('year', this.year) console.log('watch', this._watchers) console.log('methods', this.methodsAvailable) console.log('computed', this.time) console.log('------------end-------------') console.log('') } } </script>
<style scoped></style>
|