radio.js 933 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. var _ = require('../../util')
  2. module.exports = {
  3. bind: function () {
  4. var self = this
  5. var el = this.el
  6. var number = this.param('number') != null
  7. var expression = this.param('exp')
  8. var scope = this._scope || this.vm
  9. if (process.env.NODE_ENV !== 'production' && expression) {
  10. _.deprecation.MODEL_EXP(this.expression)
  11. }
  12. this.getValue = function () {
  13. // value overwrite via bind-value
  14. if (el.hasOwnProperty('_value')) {
  15. return el._value
  16. }
  17. var val = el.value
  18. if (number) {
  19. val = _.toNumber(val)
  20. } else if (expression !== null) {
  21. val = scope.$eval(expression)
  22. }
  23. return val
  24. }
  25. this.on('change', function () {
  26. self.set(self.getValue())
  27. })
  28. if (el.checked) {
  29. this._initValue = this.getValue()
  30. }
  31. },
  32. update: function (value) {
  33. this.el.checked = _.looseEqual(value, this.getValue())
  34. }
  35. }