我有一个表单可以向数组中添加新项目,但希望在用户准备添加项目之前隐藏该表单。表格是隐藏的,我有一个
@click
附加到图标的函数,用于切换要显示的窗体,该功能也在工作。但是,一旦窗体切换到显示,它就会在几秒钟内自动隐藏。
@点击图标
<li class="m-portlet__nav-item">
<a href="" class="m-portlet__nav-link m-portlet__nav-link--icon" @click="isSection ^= true">
<i class="flaticon-add"></i>
</a>
</li>
类型
<div class="row" v-show="isSection">
<div class="col-md-12">
<div style="border: 1px solid #fcfcfc; padding: 1em">
<h5>Add New Section</h5>
<hr>
<form v-on:submit.prevent="addNewSection">
<div class="form-group m-form__group">
<input v-model="sections.name" placeholder="Name" class="form-control m-input" style="margin-bottom: .5rem"/>
<textarea v-model="sections.description" placeholder="Description" class="form-control m-input" style="margin-bottom: .5rem"/></textarea>
<button type="submit" class="btn btn-primary">Add Section</button>
</div>
</form>
</div>
</div>
</div>
剧本
new Vue({
el: "#main",
data: {
isSection: false,
...
addNewSection
addNewSection() {
this.sections.push(
{
name: this.sections.name,
description: this.sections.description,
items: []
}
);
this.sections.name = "";
this.sections.description = "";
},