【发布时间】:2021-04-30 17:25:51
【问题描述】:
循环通过 vue.js 中的 <a> 属性时出现无限循环错误。
我有一个循环并动态添加属性的方法,但是当我通过将其绑定到<a> 中的属性来使用该方法时,我从标题中得到了错误。属性是原始 products 对象数组中的嵌套对象。
Vue 代码
<template>
<div>
<p>
<a
v-for="product in products"
:href="product.product_url"
type="submit"
v-bind:additionalAttrs="addAttributes()"
>
Click Me
</a>
</p>
</div>
</template>
<script>
export default {
data () {
return {
addedAttributes: [],
};
},
props: {
products: Array,
},
methods: {
addAttributes() {
this.products.forEach(product => {
for (const [key, value] of Object.entries(product.attributes)) {
this.addedAttributes.push(`${key}: ${value}`);
}
});
}
}
}
</script>
【问题讨论】:
标签: vue.js