【发布时间】:2021-06-20 22:26:35
【问题描述】:
在 vuejs 中,元素被分配一个以 'data-v-***' 开头的属性
我找不到任何有关获取此值的文档,因此最终使用 refs 并获取主节点的属性:
<template>
<div class="m-colour-picker" ref="thisContainer">
...
</div>
</template>
const attributes = this.$refs.thisContainer.getAttributeNames();
let dataAttribute = '';
attributes.forEach((attribute: string) => {
if (attribute.substring(0, 5) === 'data-') {
dataAttribute = attribute;
}
});
但是感觉有点勉强..vue中有没有方法可以获取这个已经内置的?
【问题讨论】: