github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/themes/wind/static/libs/vue-1.0.24/src/directives/public/model/index.js (about)

     1  import { warn, resolveAsset } from '../../../util/index'
     2  import { MODEL } from '../../priorities'
     3  import text from './text'
     4  import radio from './radio'
     5  import select from './select'
     6  import checkbox from './checkbox'
     7  
     8  const handlers = {
     9    text,
    10    radio,
    11    select,
    12    checkbox
    13  }
    14  
    15  export default {
    16  
    17    priority: MODEL,
    18    twoWay: true,
    19    handlers: handlers,
    20    params: ['lazy', 'number', 'debounce'],
    21  
    22    /**
    23     * Possible elements:
    24     *   <select>
    25     *   <textarea>
    26     *   <input type="*">
    27     *     - text
    28     *     - checkbox
    29     *     - radio
    30     *     - number
    31     */
    32  
    33    bind () {
    34      // friendly warning...
    35      this.checkFilters()
    36      if (this.hasRead && !this.hasWrite) {
    37        process.env.NODE_ENV !== 'production' && warn(
    38          'It seems you are using a read-only filter with ' +
    39          'v-model="' + this.descriptor.raw + '". ' +
    40          'You might want to use a two-way filter to ensure correct behavior.',
    41          this.vm
    42        )
    43      }
    44      var el = this.el
    45      var tag = el.tagName
    46      var handler
    47      if (tag === 'INPUT') {
    48        handler = handlers[el.type] || handlers.text
    49      } else if (tag === 'SELECT') {
    50        handler = handlers.select
    51      } else if (tag === 'TEXTAREA') {
    52        handler = handlers.text
    53      } else {
    54        process.env.NODE_ENV !== 'production' && warn(
    55          'v-model does not support element type: ' + tag,
    56          this.vm
    57        )
    58        return
    59      }
    60      el.__v_model = this
    61      handler.bind.call(this)
    62      this.update = handler.update
    63      this._unbind = handler.unbind
    64    },
    65  
    66    /**
    67     * Check read/write filter stats.
    68     */
    69  
    70    checkFilters () {
    71      var filters = this.filters
    72      if (!filters) return
    73      var i = filters.length
    74      while (i--) {
    75        var filter = resolveAsset(this.vm.$options, 'filters', filters[i].name)
    76        if (typeof filter === 'function' || filter.read) {
    77          this.hasRead = true
    78        }
    79        if (filter.write) {
    80          this.hasWrite = true
    81        }
    82      }
    83    },
    84  
    85    unbind () {
    86      this.el.__v_model = null
    87      this._unbind && this._unbind()
    88    }
    89  }