var _ = require('../util') var Watcher = require('../watcher') module.exports = { priority: 900, bind: function () { var vm = this.vm if (this.el !== vm.$el) { _.warn( 'v-with can only be used on instance root elements.' ) } else if (!vm.$parent) { _.warn( 'v-with must be used on an instance with a parent.' ) } else { var key = this.arg this.watcher = new Watcher( vm.$parent, this.expression, key ? function (val) { vm.$set(key, val) } : function (val) { vm.$data = val } ) // initial set var initialVal = this.watcher.value if (key) { vm.$set(key, initialVal) } else { vm.$data = initialVal } } }, unbind: function () { if (this.watcher) { this.watcher.teardown() } } }