index.js 935 B

12345678910111213141516171819202122232425262728293031323334
  1. // 当目标变量为空时显示空文案
  2. const emptyChange = (el, binding, vnode) => {
  3. // binding.value为文本 配合v-html 使用
  4. if (typeof binding.value === 'string') {
  5. if (!vnode.data.domProps.innerHTML.trim()) {
  6. el.classList.add('gray-color')
  7. el.innerHTML = binding.value
  8. } else {
  9. el.classList.remove('gray-color')
  10. }
  11. return
  12. }
  13. // binding.value为对象{open:true,text:'空文案'} 配合v-model 使用
  14. let isEmpty = false
  15. if (binding.value.open) {
  16. if (!vnode.data.model.value) {
  17. isEmpty = true
  18. }
  19. }
  20. if (isEmpty) {
  21. el.classList.add('hide-child', 'gray-color')
  22. el.appendChild(document.createTextNode(binding.value.text))
  23. } else {
  24. if (el.classList.contains('hide-child')) {
  25. el.classList.remove('hide-child', 'gray-color')
  26. el.removeChild(el.lastChild)
  27. }
  28. }
  29. }
  30. const empty = {
  31. bind: emptyChange,
  32. update: emptyChange
  33. }
  34. export { empty }