实例生命周期

var vm = new Vue({
data: {
a: 1
},
created: function () {
// `this` 指向 vm 实例
console.log('a is: ' + this.a)
}
})
// -> "a is: 1"

There are also other hooks which will be called at different stages of the instance’s lifecycle, for example mountedupdated, and destroyed. All lifecycle hooks are called with their this context pointing to the Vue instance invoking it. You may have been wondering where the concept of “controllers” lives in the Vue world and the answer is: there are no controllers. Your custom logic for a component would be split among these lifecycle hooks.

也有一些其它的钩子,在实例生命周期的不同阶段调用,如 mounted、 updated 、destroyed 。钩子的 this 指向调用它的 Vue 实例。一些用户可能会问 Vue.js 是否有“控制器”的概念?答案是,没有。组件的自定义逻辑可以分布在这些钩子中。

生命周期图示

下图说明了实例的生命周期。你不需要立马弄明白所有的东西,不过以后它会有帮助。

最新文章

  1. HTTP 错误 404.3 – Not Found 由于扩展配置问题而无法提供您请求的页面。如果该页面是脚本,请添加处理程序。如果应下载文件,请添加 MIME 映射。
  2. Enabling Cross-Origin Requests in ASP.NET Web API 2
  3. ubuntu1404服务器版中设置root用户
  4. main函数的argc和argv
  5. 编译QT时出现lib/libQtGui.so: undefined reference to `ts_read_raw'的解决办法
  6. 结对开发--课堂练习--c++
  7. Redis与Memcached的incr/decr差异对比
  8. EffectiveC#02--仅在对基类进行强制更新时才使用new修饰符
  9. 一个关于css3背景透明的例子
  10. lucene4.4 索引的增删改查
  11. Linux使用rsync客户端与服务端同步目录进行备份
  12. [android游戏开发初学]SurfaceView初探之缓冲区测试
  13. 张高兴的 Windows 10 IoT 开发笔记:使用 MAX7219 驱动 8×8 点阵
  14. openstack-ocata-计算服务4
  15. /etc/shadow中密码段的生成方式
  16. Uva 11178 Morley定理
  17. [openjudge-动态规划]鸣人的影分身
  18. 微信小程序倒计时组件开发
  19. kafka 支持发布订阅
  20. js实现获取URL参数

热门文章

  1. ios学习笔记之2天来总结
  2. WPF中StackPanel的使用方法
  3. SharePoint RBS 安装(集成Office Web Apps)
  4. JUC.Condition学习
  5. CSS样式基础知识
  6. 40w会议投票系统优化方案
  7. #2006 - MySQL server has gone away 问题解决方法 (全) (转)
  8. 【实用技巧】去除BootStrap所有圆角效果
  9. 使用div模拟textarea,实现文本输入框高度自适应(附:js控制textarea实现文本输入框高度自适应)
  10. VR电影这一新概念在中国电影道路上的探索