工厂函数/构造函数 参数选项

1. options: Object

工厂函数/构造函数 的参数选项
默认值: {}

1.1. el: String

上下文 dom selector
默认值: undefined

1.2. tagName: String

没传递 el 参数, 将用 tagName 创建一个 dom 上下文
默认值: 'div'

1.3. events: Object

绑定 dom 监听事件
默认值: {}
实例:

source code

1.4. data: Object

view 的抽象 model
默认值: {}
可以利用实例的 set / get 方法来设置 / 获取对应的值

var App = Vir()
var app = new App({
  data: {
    index: 0
  }
})

console.log(app.get('index')) // => 0
app.set('index', 1)
console.log(app.get('index')) // => 1

1.5. methods: Object

实例化的时候 合并实例对象
默认值: {}

var App = Vir()
var app = new App({
  methods: {
    handler: function() {}
  }
})
console.log(app.handler) // => function

1.6. watch: Object

set 一个 model 的时候触发对应回调
默认值: {}

var App = Vir()
var app = new App({
  el: '#demo',
  data: {
    index: 0
  },
  watch: {
    index: function(result) {
      alert(JSON.stringify(result))
    }
  }
})

app.set('index', 100)

1.7. validate: Object

set 的时候验证钩子

var App = Vir()
var app = new App({
  el: '#demo',
  data: {
    index: 0
  },
  validate: {
    index: function(result) {
      alert('验证 index:' + result.value)
      if (result.value > 100) {
        return false
      }
    }
  },
  watch: {
    index: function(result) {
      alert(JSON.stringify(result))
    }
  }
})

app.set('index', 100)
app.set('index', 101) // 失败

1.8. beforeInit: Function

初始化完成前执行

1.9. init: Function

实例初始化完成执行

1.10. inited: Function

init 完成后执行

results matching ""

    No results matching ""