Dialog组件的使用方法
这篇文章主要介绍“Dialog组件的使用方法”,在日常操作中,相信很多人在Dialog组件的使用方法问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”Dialog组件的使用方法”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
1.Dialog用法
<el-dialog title="新增巡检模板" :visible.sync="addDialog" width="40%"> <el-form ref='addForm' :rules="rules" :model='addForm' label-width="80px"> <el-form-item label="选择业务" prop="bk_biz"> <el-select v-model="addForm.add_bk_biz" placeholder="请输入业务名称" class="modal1" > <el-option v-for="item in bkBizData" :value="item.bk_biz_id +':'+item.bk_biz_name" :label="item.bk_biz_name"> </el-option> </el-select> </el-form-item> <el-form-item label="模板名称" prop="temp_name"> <el-input v-model="addForm.add_temp_name" placeholder="请输入模板名称" class="modal1"></el-input> </el-form-item> <el-form-item label="巡检脚本" prop="temp_script"> <el-input v-model="addForm.add_temp_script" type="textarea" placeholder="请输入巡检脚本" class="modal1"></el-input> </el-form-item> <el-form-item label="模板阀值" prop="temp_value"> <el-input v-model="addForm.add_temp_value" placeholder="请输入模板阀值" class="modal1"></el-input> </el-form-item> <el-form-item label="模板备注" prop="temp_note"> <el-input v-model="addForm.add_temp_note" type="textarea" placeholder="请输入备注" class="modal1"></el-input> </el-form-item> <el-form-item> <el-button type="primary" @click="addDialogOk">立即创建</el-button> <el-button @click="addDialog = false">取消</el-button> </el-form-item> </el-form> </el-dialog>
对应js代码
<script type="text/javascript"> new Vue({ el: '#app', data: { bkBizData: [], addDialog:false, addForm: { add_bk_biz: '', add_temp_name: '', add_temp_script: '', add_temp_note: '', add_temp_threshold: '' }, rules: { bk_biz: [ { required: true, message: '请选择业务', trigger: 'change' } ], temp_name: [ { required: true, message: '请输入模板名称', trigger: 'blur' }, { min: 2, max: 8, message: '长度在 2 到 8 个字符', trigger: 'change' } ], temp_script: [ { required: true, message: '请输入巡检脚本', trigger: 'blur' } ], temp_note: [ { required: true, message: '请输入备注', trigger: 'blur' }, { min: 2, message: '长度最少2位', trigger: 'blur' } ], temp_value: [ { type: 'number', required: true, message: '请输入阈值', trigger: 'change' } ] } }, mounted() { // 页面加载就获取所有模板 this.init() }, methods: { init() { axios.get(site_url + "get_biz_list/").then(res => { if (res.data.result){ this.bkBizData = res.data.data; }else{ this.$message.error('获取业务失败'); } },'json'); this.getSearch(); }, getSearch() { axios.get(site_url + "temp_view/?search_biz=" + this.searchBiz + "&query_str=" + this.searchTempName).then(res => { if (res.data.result){ this.tempData = res.data.data; }else{ this.$message.error('获取模板失败'); } },'json'); }, addDialogOk() { this.$refs['addForm'].validate((valid) => { if (valid) { axios.post(site_url + "temp_view/", this.addForm).then(res => { if (res.data.result) { this.$message.success('添加模板成功'); this.addDialog = false; this.getSearch(); this.addForm = { add_bk_biz: '', add_temp_name: '', add_temp_script: '', add_temp_value: '', add_temp_note: '' } } else { this.$message.error('添加模板失败'); } }, 'json'); } else { console.log('error submit!!'); return false; } }) }, ... } }) </script>
到此,关于“Dialog组件的使用方法”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注网站,小编会继续努力为大家带来更多实用的文章!