theme.js 1.08 KB
export const theme = {
  /**
   * @description: bind
   * @param {*} el
   * @param {*} binding
   * @param {*} vnode
   * @author: renchao
   */
  bind: function (el, binding, vnode) {
    setEleStyleColorAttribute(el, binding);
  },
  /**
   * @description: update
   * @param {*} el
   * @param {*} binding
   * @param {*} vnode
   * @author: renchao
   */
  update: function (el, binding, vnode) {
    setEleStyleColorAttribute(el, binding);
  },
  /**
   * @description: componentUpdated
   * @param {*} el
   * @param {*} binding
   * @param {*} vnode
   * @author: renchao
   */
  componentUpdated: function (el, binding, vnode) {
    setEleStyleColorAttribute(el, binding);
  }
}

/**
 * @description: setEleStyleColorAttribute
 * @param {*} el
 * @param {*} binding
 * @author: renchao
 */
function setEleStyleColorAttribute (el, binding) {
  const { name, value, arg, expression, modifiers } = binding;
  const { background, font, border } = modifiers;
  if (background) el.style['background-color'] = value;
  if (font) el.style.color = value;
  if (border) el.style['border-color'] = value;
}