Переглянути джерело

x-if warn if used on non-template (#3737)

jonas-grobe 1 рік тому
батько
коміт
87d65fc8cc
1 змінених файлів з 3 додано та 0 видалено
  1. 3 0
      packages/alpinejs/src/directives/x-if.js

+ 3 - 0
packages/alpinejs/src/directives/x-if.js

@@ -5,8 +5,11 @@ import { initTree } from '../lifecycle'
 import { mutateDom } from '../mutation'
 import { walk } from "../utils/walk"
 import { dequeueJob } from '../scheduler'
+import { warn } from "../utils/warn"
 
 directive('if', (el, { expression }, { effect, cleanup }) => {
+    if (el.tagName.toLowerCase() !== 'template') warn('x-if can only be used on a <template> tag', el)
+
     let evaluate = evaluateLater(el, expression)
 
     let show = () => {