摘要:网上关于生命周期的文章一抓一大把看了很多收获是有的但纸上得来终觉浅最终还是决定自己上手加深一下印象测试版本程序设计如下程序运行结果如下加载时卸载时以下是我的总结不对的地方欢迎拍砖钩子调用时获取中的属性得到获取中的属性
网上关于vue生命周期的文章一抓一大把, 看了很多, 收获是有的, 但纸上得来终觉浅. 最终还是决定自己上手,加深一下印象
测试版本
vue 2.5.2
程序设计如下
</>复制代码
function log() {
try {
console.log("%c%s", "color: blue", `===============data:foo ---> ${this.foo}=====================`)
} catch (e) {
}
try {
console.log("%c%s", "color: blue", `===============props:bar ---> ${this.bar}=====================`)
} catch (e) {
}
try {
console.log("%c%s", "color: blue", `===============computed:baz ---> ${this.baz}=====================`)
} catch (e) {
}
try {
console.log("%c%s", "color: blue", `===============computed:bzz ---> ${this.bzz}=====================`)
} catch (e) {
}
}
export default {
data() {
return {
foo: "foo"
}
},
props: {
bar: {type: String, "default": "bar"}
},
computed: {
baz() {
return this.foo + this.bar
},
bzz() {
return this.method()
}
},
beforeCreate() {
console.log("%c%s", "color: red", "
===============beforeCreate called===============")
log.call(this)
},
created() {
console.log("%c%s", "color: red", "
===============created called===============")
log.call(this)
},
mounted() {
console.log("%c%s", "color: red", "
===============mounted called===============")
log.call(this)
},
methods: {
method() {
return "method"
}
},
beforeDestroy() {
console.log("%c%s", "color: red", "
===============beforeDestroy called===============")
log.call(this)
},
destroyed() {
console.log("%c%s", "color: red", "
===============destroyed called===============")
log.call(this)
}
}
程序运行结果如下:
</>复制代码
加载时:
</>复制代码
卸载时:
以下是我的总结(不对的地方欢迎拍砖):
beforeCreate 钩子调用时:
获取data中的属性 得到undefined
获取props中的属性 报错
获取computed中的属性 得到undefined
其他钩子函数中均能正常的获取到所有的值
值得注意的是 在created钩子执行后 computed 属性函数中可以访问到 data props methods 中的值
甚至在destroyed 函数中依然能够正常的访问到这些值.
欢迎挑错 ^_^
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/90186.html
摘要:如上图,该图没有现成的,所以是在大师原有的上修改出来的我们在开发过程中,通常以当天下午下班前十分钟为节点,合并当日修复的代码到分支另外要说的就是分支的命名了,通常我们已即将发布的版本号为后缀添加到后面,例如等等。 showImg(https://segmentfault.com/img/remote/1460000015968861?w=1920&h=1080); 首发公众号:Andr...
阅读 634·2023-04-25 17:26
阅读 1633·2021-08-05 09:58
阅读 2048·2019-08-30 13:17
阅读 1045·2019-08-28 17:52
阅读 1156·2019-08-26 18:27
阅读 1495·2019-08-26 14:05
阅读 3730·2019-08-26 14:05
阅读 1794·2019-08-26 10:45