# 实现修改
# 思路
1. 通过点击修改按钮触发模态框,弹出模态框,
2. 修改模态框中的数据响应到页面中
# HTML
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| <div id="app"> <button type="button"@click="gai(index,item)" class="btn btn-primary" data-toggle="modal" data-target="#myModal">修改</button> <div class="container"> <div class="modal fade" id="myModal"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <h4 class="modal-title">修改</h4> <button type="button" class="close" data-dismiss="modal">×</button> </div> <div class="modal-body"> <div v-show="shou"> <input type="" v-model="form.name" name="" id="" value="" /> <input type="" v-model="form.age" name="" id="" value="" /> <button type="button" @click="an()">确定</button> </div> </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button> </div> </div> </div> </div> </div> </div>
|
# js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| let vm=new Vue({ el:"#app", data:{ shou:false, form: { name: '', age: '' }, name: '', age: '', radio: '', checked: [], sao: '', live: '', index:'' }, methods: { gai(i, k) { this.shou = !this.shou; this.form.name = k.name; this.form.age = k.age; this.index = i; }, an() { this.arr[this.index].name = this.form.name; this.arr[this.index].age = this.form.age; }, } })
|