فهرست منبع

adjust binding attr retrieval priority

Evan You 10 سال پیش
والد
کامیت
20f6e6e3fe
1فایلهای تغییر یافته به همراه13 افزوده شده و 6 حذف شده
  1. 13 6
      src/compiler/helpers.js

+ 13 - 6
src/compiler/helpers.js

@@ -70,14 +70,21 @@ export function getBindingAttr (
   el: ASTElement,
   name: string,
   getStatic?: boolean
-) {
-  const staticValue = getStatic !== false && getAndRemoveAttr(el, name)
-  return staticValue || staticValue === ''
-    ? JSON.stringify(staticValue)
-    : (getAndRemoveAttr(el, ':' + name) || getAndRemoveAttr(el, 'v-bind:' + name))
+): ?string {
+  const dynamicValue =
+    getAndRemoveAttr(el, ':' + name) ||
+    getAndRemoveAttr(el, 'v-bind:' + name)
+  if (dynamicValue != null) {
+    return dynamicValue
+  } else if (getStatic !== false) {
+    const staticValue = getAndRemoveAttr(el, name)
+    if (staticValue != null) {
+      return JSON.stringify(staticValue)
+    }
+  }
 }
 
-export function getAndRemoveAttr (el: ASTElement, name: string) {
+export function getAndRemoveAttr (el: ASTElement, name: string): ?string {
   let val
   if ((val = el.attrsMap[name]) != null) {
     el.attrsMap[name] = null