vue3+element-plusfor循环获取ref使⽤⽅法<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>vue3+element-plus for循环获取ref使⽤⽅法</title>
</head>
<body>
<div id="app">
<h3>vue3+element-plus for循环获取ref使⽤⽅法</h3>
<el-row v-for="(itemForm, i) in listForms">
<el-form :model="itemForm" :ref="el => { if (el) listFormRefs[i] = el }" :rules="rules" label-width="100px" class="demo-registerForm">
<el-form-item label="⼿机号" prop="phone">
<el-input v-model="itemForm.phone"></el-input>
</el-form-item>
<el-form-item label="密码" prop="password">
<el-input v-model="itemForm.password"></el-input>
</el-form-item>
</el-form>
<el-button @click="removeForm(i)">移除</el-button>
</el-row>
<el-button @click="addForm()">添加</el-button>
<el-button type="primary" @click="registerSubmitAll()">提交全部</el-button>
</div>
</body>
<!-- 引⼊ Vue -->
<!-- <script src="//unpkg/vue@next"></script> -->
<script src="lib/vue/vue@3.2.9-global.js"></script>
<!-- 引⼊样式 -->
<!-- <link rel="stylesheet" href="//unpkg/element-plus/dist/index.css" /> -->
<link rel="stylesheet" href="lib/element-ui/element-plus@1.1.0-beta.9.css" />
<!-- 引⼊组件库 -->
<!-- <script src="//unpkg/element-plus"></script> -->
<script src="lib/element-ui/element-plus@1.1.0-beta.9.js"></script>
<script>
let app = ateApp({
mounted() {},
vue element adminsetup() {
const ref = f;
const reactive = active;
const toRefs = Refs;
const onMounted = Mounted;
const onBeforeUpdate = BeforeUpdate;
const listFormRefs = ref([]);
const state = reactive({
listForms: [{ id: 1 }],
rules: {
phone: [{ required: 'true', message: '账户不能为空', trigger: 'blur' }],
password: [{ required: 'true', message: '密码不能为空', trigger: 'blur' }],
},
});
// 确保在每次更新之前重置ref
onBeforeUpdate(() => {
console.log('');
listFormRefs.value = [];
});
const addForm = () => {
state.listForms.push({ id: w() });
};
const removeForm = (i) => {
state.listForms.splice(i, 1);
};
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论