Skip to content
Discussion options

You must be logged in to vote

Vue does have normalization helpers for this, but I would be careful about treating them as a public “apply this to any DOM element” API.

For classes, normalizeClass is the closest fit:

import { normalizeClass } from "vue";

div.className = normalizeClass(attrs.class);

For styles, normalizeStyle can normalize Vue’s accepted :style shapes into an object or string form:

import { normalizeStyle } from "vue";

const normalized = normalizeStyle(attrs.style);

Then you can apply it manually:

import { normalizeClass, normalizeStyle, watchEffect } from "vue";

watchEffect(() => {
  const el = div.value;

  if (!el) {
    return;
  }

  el.className = normalizeClass(attrs.class);

  const style = n…

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@rtcpw
Comment options

Comment options

You must be logged in to vote
1 reply
@rtcpw
Comment options

Answer selected by rtcpw
Comment options

You must be logged in to vote
1 reply
@rtcpw
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants