with.js 648 B

123456789101112131415161718192021222324252627282930
  1. var _ = require('../util')
  2. module.exports = {
  3. priority: 900,
  4. bind: function () {
  5. if (!this.arg) {
  6. // by default, components have _noSync:true
  7. // but when there's no arg it means we are
  8. // inheriting a parent object as $data, so we have
  9. // to sync the chagnes
  10. this.vm.$options._noSync = false
  11. }
  12. var self = this
  13. var path = this.arg || '$data'
  14. this.vm.$watch(path, function (val) {
  15. self.set(_.toNumber(val))
  16. })
  17. },
  18. update: function (value) {
  19. if (this.arg) {
  20. this.vm.$set(this.arg, value)
  21. } else if (this.vm.$data !== value) {
  22. this.vm.$data = value
  23. }
  24. }
  25. }