2
0
Эх сурвалжийг харах

Merge pull request #1639 from fergaldoyle/dev

IE title binding issue
Evan You 10 жил өмнө
parent
commit
995b096fa1

+ 8 - 2
src/compiler/compile-props.js

@@ -21,7 +21,7 @@ module.exports = function compileProps (el, propOptions) {
   var props = []
   var names = Object.keys(propOptions)
   var i = names.length
-  var options, name, attr, value, path, parsed, prop
+  var options, name, attr, value, path, parsed, prop, isTitleBinding
   while (i--) {
     name = names[i]
     options = propOptions[name] || empty
@@ -50,10 +50,16 @@ module.exports = function compileProps (el, propOptions) {
       mode: propBindingModes.ONE_WAY
     }
 
+    // IE title issues
+    isTitleBinding = false
+    if (name === 'title' && (el.getAttribute(':title') || el.getAttribute('v-bind:title'))) {
+      isTitleBinding = true
+    }
+
     // first check literal version
     attr = _.hyphenate(name)
     value = prop.raw = _.attr(el, attr)
-    if (value === null) {
+    if (value === null || isTitleBinding) {
       // then check dynamic version
       if ((value = _.getBindAttr(el, attr)) === null) {
         if ((value = _.getBindAttr(el, attr + '.sync')) !== null) {

+ 44 - 0
test/unit/specs/misc_spec.js

@@ -269,4 +269,48 @@ describe('Misc', function () {
     })
     expect(hasWarned(__, 'Unknown custom element')).toBe(true)
   })
+
+  it('prefer bound title over static title', function (done) {
+    var el = document.createElement('div')
+    var count = 0
+    var expected = [
+      'bound',
+      'bound',
+      'static',
+      'bound',
+      'bound'
+    ]
+    function check (title) {
+      expect(title).toBe(expected[count])
+      count++
+      if (count === 4) {
+        done()
+      }
+    }
+
+    document.body.appendChild(el)
+
+    new Vue({
+      el: el,
+      template:
+        '<div>\
+          <comp v-bind:title="title"></comp>\
+          <comp title="static" v-bind:title="title"></comp>\
+          <comp title="static"></comp>\
+          <comp :title="title"></comp>\
+          <comp title="static" :title="title"></comp>\
+        </div>',
+      data: {
+        title: 'bound'
+      },
+      components: {
+        comp: {
+          props: ['title'],
+          ready: function () {
+            check(this.title)
+          }
+        }
+      }
+    })
+  })
 })