element-ui의 dialog 플러그인 추가 사용자 기능

10581 단어
// 
<el-button @click="dialogvisible = true">   </el-button>
//dialog 
<el-dialog title=" " :visible.sync="dialogVisible"  width="50%">
//el-form 
  <el-form :model="UserForm" :rules="UserRules" ref="UserRef" label-width="80px">
  	<el-form-item label=" " prop="username">
    	<el-input v-model="UserForm.username"></el-input>
  	</el-form-item>
  </el-form>
  
  <span slot="footer" class="dialog-footer">
    <el-button @click="closedUserForm">   </el-button>
    <el-button type="primary" @click="dialogVisible = false" @click="addUserForm">   </el-button>
  </span>
</el-dialog>
data(){
	return{
		UserForm:[
			{username:''}
		],
		UserRules: {
          username: [
            { required: true, message: ' ', trigger: 'blur' },
            { min: 3, max: 5, message: '  3   5  ', trigger: 'blur' }
          	],
          }
	}
}
methods:{
	// 
	closedUserForm(){
		this.dialogvisible = false	// dialog 
		this.$refs.UserRef.resetFields();	// 
	},
	// 
	addUserForm(){
	this.$refs.UserRef.validate(async (valid)=>{
		if(!valid) return
		const {data:res} = await this.$http.post("roles", this.UserForm)
		if(res.meta.status!==201) return this.$message.error(' ')
		this.$message.success(' ')
		this.dialogvisible = false	// dialog 
		this.getUserList() // 
	})
	}
}

좋은 웹페이지 즐겨찾기