英文:
How to return the properties of CSS.registerProperty()
问题
I have 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 am looking for a way to know if there is a getter for properties or similar.
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)
}
}
}
That's the error -> DOMException: Failed to execute 'registerProperty' on 'CSS': The name provided has already been registered.
英文:
I have 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 am looking for a way to know if there is a getter for properties or similar.
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)
}
}
}
That's the error -> DOMException: Failed to execute 'registerProperty' on 'CSS': The name provided has already been registered.
答案1
得分: 1
根据规范:
https://drafts.css-houdini.org/css-properties-values-api/#registering-custom-properties
Document 对象增加了一个新的 [[registeredPropertySet]] 私有槽,它是描述注册的自定义属性的记录集合。
据我所知,这正是 Chrome 实现的方式。绝对没有意图访问 [[registeredPropertySet]]
的设计机制,所以你已经在使用可能是最佳的可行方法:try / catch
。与该集合发生冲突的任何属性名称都会抛出一个语法错误。
英文:
From the spec:
https://drafts.css-houdini.org/css-properties-values-api/#registering-custom-properties
> the Document object gains a new [[registeredPropertySet]] private slot, which is a set of records that describe registered custom properties.
As far as I can tell, that is exactly how Chrome has implemented it. There is absolutely no intentional mechanism designed to access the [[registeredPropertySet]]
, so you are already using what might be the best viable approach: try / catch
. Any property name colliding with that set will throw a syntax error.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论