VUE动态控制表单是否被编辑

有的时候,有那么一个需求,就是查看表单的时候不允许编辑,有的时候允许编辑,所以就有了如下经验

 <el-form ref="form" :model="form" :rules="rules" label-width="20%" :disabled='this.title==="查看"'></el-form>

一个比较取巧的行为就是使用了:disabled='this.title==="查看"' 只要满足条件表单就不允许编辑

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
同样地,我们可以在Vue2项目中使用Bootstrap弹窗来实现可编辑表单的功能。以下是一个简单的示例: ``` <template> <div> <!-- 弹窗按钮 --> <button type="button" class="btn btn-primary" @click="openModal">打开弹窗</button> <!-- 弹窗 --> <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <h4 class="modal-title" id="myModalLabel">{{ title }}</h4> <button type="button" class="close" data-dismiss="modal" aria-label="Close" @click="closeModal"><span aria-hidden="true">×</span></button> </div> <div class="modal-body"> <form> <div class="form-group"> <label for="inputName">姓名</label> <input type="text" class="form-control" id="inputName" placeholder="请输入姓名" v-model="name"> </div> <div class="form-group"> <label for="inputEmail">邮箱</label> <input type="email" class="form-control" id="inputEmail" placeholder="请输入邮箱" v-model="email"> </div> <div class="form-group"> <label for="inputPassword">密码</label> <input type="password" class="form-control" id="inputPassword" placeholder="请输入密码" v-model="password"> </div> </form> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal" @click="closeModal">关闭</button> <button type="button" class="btn btn-primary" @click="saveData">保存</button> </div> </div> </div> </div> </div> </template> <script> export default { data() { return { title: '编辑表单', name: '', email: '', password: '' } }, methods: { openModal() { $('#myModal').modal('show'); }, closeModal() { $('#myModal').modal('hide'); }, saveData() { // 在这里处理保存数据的逻辑 this.closeModal(); } } } </script> ``` 在上面的示例中,我们使用了Bootstrap的modal组件来实现弹窗的功能。在Vue组件中,我们可以通过点击按钮来打开弹窗,并在弹窗中嵌入一个表单表单的各个输入框使用v-model指令来绑定数据,在保存数据时,我们可以在saveData方法中编写逻辑来处理数据的保存。 需要注意的是,为了在Vue中使用jQuery来控制Bootstrap组件,我们需要在项目中引入jQuery和Bootstrap的相关JS文件。可以在Vue项目的public/index.html文件中引入这些文件: ``` <!DOCTYPE html> <html> <head> ... </head> <body> <div id="app"></div> <!-- 引入jQuery和Bootstrap的JS文件 --> <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script src="https://cdn.bootcdn.net/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script> <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.5.3/js/bootstrap.min.js"></script> <script src="/js/app.js"></script> </body> </html> ``` 在上面的示例中,我们使用的是Bootstrap 4版本的JS文件,如果你使用的是其他版本的Bootstrap,请相应地修改引入的JS文件的路径。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值