search

Home  >  Q&A  >  body text

Learn how to get the property value of CSS.registerProperty()

I registered a property through the CSS.registerProperty method. The problem is that when I load the same component, a DOMException is thrown because such a property already exists.

I'm looking for a way to determine if there is a getter method for a similar property.

Run in a vue3 component.

onMounted( () => {
  try {
      window.CSS.registerProperty({
    name: "--num",
    syntax: "<integer>",
    inherits: false,
    initialValue: 0,
  });
  } catch (error) {
    if(error instanceof DOMException){
      console.log(error)
    }
  }
}

This is the error message -> DOMException: Failed to execute 'registerProperty' on 'CSS': The name provided has already been registered.

P粉293341969P粉293341969233 days ago382

reply all(1)I'll reply

  • P粉715228019

    P粉7152280192024-03-31 21:18:45

    From specification: https://drafts.css-houdini.org/css-properties-values-api/#registering-custom-properties

    As far as I know, this is exactly how Chrome implements it. There's no intentional mechanism designed to access [[registeredPropertySet]], so you're already using what's probably the best possible approach: try/catch. Any property name that conflicts with this collection will throw a syntax error.

    reply
    0
  • Cancelreply