Evan You преди 10 години
родител
ревизия
42dc999944
променени са 2 файла, в които са добавени 22 реда и са изтрити 0 реда
  1. 8 0
      src/directives/el.js
  2. 14 0
      test/unit/specs/directives/el_spec.js

+ 8 - 0
src/directives/el.js

@@ -11,6 +11,14 @@ module.exports = {
     var id = this.id = this.arg // bind-el ?
       ? scope.$eval(this.expression)
       : this.expression
+
+    if (process.env.NODE_ENV !== 'production' && this.arg) {
+      _.log(
+        'You are using bind- syntax on "el", which is a special ' +
+        'attribute. It will be evaluated only once.'
+      )
+    }
+
     if (refs.hasOwnProperty(id)) {
       refs[id] = this.el
     } else {

+ 14 - 0
test/unit/specs/directives/el_spec.js

@@ -8,6 +8,7 @@ if (_.inBrowser) {
     beforeEach(function () {
       el = document.createElement('div')
       spyOn(_, 'warn')
+      spyOn(_, 'log')
     })
 
     it('normal', function () {
@@ -42,6 +43,19 @@ if (_.inBrowser) {
       })
     })
 
+    it('bind-el', function () {
+      var vm = new Vue({
+        el: el,
+        data: {
+          id: 'test'
+        },
+        template: '<div bind-el="id" id="test"></div>'
+      })
+      expect(vm.$$.test).toBeTruthy()
+      expect(vm.$$.test.id).toBe('test')
+      expect(_.log).toHaveBeenCalled()
+    })
+
     it('with v-repeat', function (done) {
       var vm = new Vue({
         el: el,