Vue实例概览

136 阅读1分钟

Vue实例(对象)

  • 基本结构:const vm=new Vue(options) options是对象
  • vm对象封装了针对视图的所有操作,如数据读写、事件、DOM更新等
  • options作为参数,一般称之为选项或者构造选项

options内部属性总览

  • 注:以下为常用属性,具体用法本篇不作详细阐述

数据

  • data 内部数据
  • props 外部数据
  • propsData
  • computed 计算数据
  • methods 方法即函数
  • wathch 监听

DOM

  • el 挂载点
  • template 在完整版里的视图
  • render 在非完整版里的视图
  • renderError 在非完整版里的视图失败了

生命周期钩子:

  • beforeCreate
  • created
  • beforeMount
  • mounted
  • beforeUpdate
  • updated
  • activated
  • deactivated
  • beforeDestroy
  • destroyed
  • errorCaptured

资源

  • directives  指令
  • filters 过滤器(不要用了),用methods代替
  • components 组件,如Demo.vue

组合

  • parent 先不看,用到再查文档
  • mixins 混入
  • extends 扩展
  • provide
  • inject 注入