vue构造选项

const vm = new Vue(options)

把Vue的实例命名为vm

vm对象封装了对视图的所有操作,包括数据读写、时间绑定、DOM更新

vm的构造函数是Vue,vm所属的类是Vue

optioins是new Vue的参数,一般称之为选项构造选项

一. options 里面有什么

1.png

2.png

3.png

1. el – 挂载点

el : Vue实例挂载的元素节点,值可以是 CSS 选择符,或实际 HTML 元素,或返回 HTML 元素的函数。

4.png

5.png

也可以用 $mount 代替

6.png

2. data – 内部数据

支持对象和函数,优先用函数会有bug

7.png

3. methods – 方法

事件处理函数或者是普通函数,必须写到methods里面否则报错

8.png

4. conponents vue组件,注意大小写

imprt Demo from'./Demo.vue'
(文件名可大写可小写,建议小写,因为window系统区分不了大小写)
(组件建议大写开头)

const vm = new Vue({
  components:{
  Demo: Demo
  }
})

上面Demo: Demo左右相等的情况下可以缩写成

components:{Demo}
复制代码

钩子

5.1 created – 实例出现在内存中

created(){
 debugger(打断点证明)
 console.log('这玩意出现在内存中,没有出现在页面中')
}

复制代码

5.2 mounted – 实例出现在页面中

mounted(){
  debugger(打断点证明) 
  console.log('这玩意出现在页面中')
  }
复制代码

5.3 updated – 实例更新了

指能保证我已经把数据更新了再触发当前的函数

updated(){
  console.log('更新了')
}
复制代码

5.4 destroyed – 实例从页面和内存中消亡、消失了

请实现这个方法

6 props – 外部数据也叫属性

1.png
message = “n” 传入字符串

:message = “n” 传入 this.n 数据

:fn = “add” 传入 this.add 函数

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享