如何在 Vue.js 中动态添加超赞字体图标
How to add a font awesome icon dynamically in Vue.js
我有两个位于模态中的输入和一个按钮,当用户单击它时会生成另外两个输入。它有效,但我只想在两个输入旁边为动态创建的输入添加一个很棒的字体图标,我如何在 Vue 中实现这一点?到目前为止,这是我的代码:
<div class="price-round-creation-containe" v-for="(shareholder, index) in shareholders" :key="index">
<div>
<input v-model="shareholder.username" :name="`shareholders[${index}][username]`" type="text" class="form-control input" >
</div>
<div>
<input v-model="shareholder.investment" :name="`shareholders[${index}][investment]`" type="text" class="form-control input" >
</div>
</div>
<p
class="add-new-shareholders-p"
@click="createNewPricedRoundShareholder"
>
<i class="fa fa-plus-circle fa-lg" />ADD NEW SHAREHOLDER
</p>
我的数据:
shareholders: [
{
investment: "Investment",
username: "Username"
},
]
以及我的添加按钮的功能:
createNewPricedRoundShareholder() {
this.shareholders.push({
username: "Username",
investment: "Investment"
},
}
您可以添加一个额外的 属性 dynamic: true
添加:
this.shareholders.push({
username: "Username",
investment: "Investment",
dynamic: true
})
并在显示输入时检查它:
<div>
<input v-model="shareholder.username" :name="`shareholders[${index}][username]`" type="text" class="form-control input" >
<i v-if="shareholder.dynamic" class="fa fa-plus-circle fa-lg" />
</div>
<div>
<input v-model="shareholder.investment" :name="`shareholders[${index}][investment]`" type="text" class="form-control input" >
<i v-if="shareholder.dynamic" class="fa fa-plus-circle fa-lg" />
</div>
我有两个位于模态中的输入和一个按钮,当用户单击它时会生成另外两个输入。它有效,但我只想在两个输入旁边为动态创建的输入添加一个很棒的字体图标,我如何在 Vue 中实现这一点?到目前为止,这是我的代码:
<div class="price-round-creation-containe" v-for="(shareholder, index) in shareholders" :key="index">
<div>
<input v-model="shareholder.username" :name="`shareholders[${index}][username]`" type="text" class="form-control input" >
</div>
<div>
<input v-model="shareholder.investment" :name="`shareholders[${index}][investment]`" type="text" class="form-control input" >
</div>
</div>
<p
class="add-new-shareholders-p"
@click="createNewPricedRoundShareholder"
>
<i class="fa fa-plus-circle fa-lg" />ADD NEW SHAREHOLDER
</p>
我的数据:
shareholders: [
{
investment: "Investment",
username: "Username"
},
]
以及我的添加按钮的功能:
createNewPricedRoundShareholder() {
this.shareholders.push({
username: "Username",
investment: "Investment"
},
}
您可以添加一个额外的 属性 dynamic: true
添加:
this.shareholders.push({
username: "Username",
investment: "Investment",
dynamic: true
})
并在显示输入时检查它:
<div>
<input v-model="shareholder.username" :name="`shareholders[${index}][username]`" type="text" class="form-control input" >
<i v-if="shareholder.dynamic" class="fa fa-plus-circle fa-lg" />
</div>
<div>
<input v-model="shareholder.investment" :name="`shareholders[${index}][investment]`" type="text" class="form-control input" >
<i v-if="shareholder.dynamic" class="fa fa-plus-circle fa-lg" />
</div>