Instance Lifecycle Hooks
Hooks到底是什么?
中文解释就是钩子,其实Vue就有点像是一个挂着一个的感觉,所以才叫Hooks(很多个所以用複数,大概是这样吧?)有找到好的解释再补上。
这里有一个提醒
就是尽量不要在fucntion使用箭头函示,因为在使用arrow function的时候,this就会不存在,因为他会提取外层的this。
ex
<div id="app"> {{ msg }}</div><script>let data = { 'msg': 'hello Vue',}let vm = new Vue({ el: "#app", data, // created:(){} // es6写法 // 这边比较 一般写法跟 arrow function created: function (){ console.log(this) // 一般写法 // 这边会指向Vue的实体 }, created: ()=>{ consloe.this(this); // 这边会直接指向window },})</script>
这边很重要的提醒就是,不要在Vue的第一层function使用arrow function,不然会很难取到这个Vue实体的值。
下一篇就是说 Template syntax