Skip to content

Commit

Permalink
- [新增] 了解在beforeCreate生命周期里面, data和methods方法是否可以被调用
Browse files Browse the repository at this point in the history
  • Loading branch information
montage-f committed Oct 5, 2019
1 parent ffe34b3 commit 90b4758
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export default new Router({
name: 'Detail',
// 当整个文件过大的时候, 我们可以采用异步组件, 进行代码的拆分
component: () => import('@/views/Detail'),
}, {
path: '/live',
name: 'Live',
component: () => import('@/views/Live'),
},
],
scrollBehavior() {
Expand Down
44 changes: 44 additions & 0 deletions src/views/Live/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**Created by montage_fz on 2019-10-05**/
<template>
<div class="Live">
生命周期测试
</div>
</template>

<script>
export default {
name: 'Live',
components: {},
data() {
return {
num: 1,
};
},
beforeCreate() {
// 当前生命周期无法获取methods里面的方法
try {
this.init('我是beforeCreate生命周期');
} catch (e) {
console.log('当前生命周期无法获取methods里面的方法');
}
},
created() {
try {
this.init('我是created生命周期');
} catch (e) {
console.log('当前生命周期无法获取methods里面的方法');
}
},
computed: {},
methods: {
init(value) {
console.log(value, this.num);
},
},
};
</script>

<style scoped lang="less">
.Live {
}
</style>

0 comments on commit 90b4758

Please sign in to comment.