wangzhibo
2026-07-16 b57020623cf0c946706573bf102e548c3a544423
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<template>
    <div class="scope">
        <div class="h">
            <el-tag size="small" effect="dark" disable-transitions>setFocus</el-tag>
            <span>自动聚焦</span>
        </div>
 
        <div class="c">
            <el-button @click="open">预览</el-button>
            <demo-code :files="['form/setFocus.vue']" />
 
            <!-- 自定义表单组件 -->
            <cl-form ref="Form"></cl-form>
        </div>
 
        <div class="f">
            <span class="date">2025-03-12</span>
        </div>
    </div>
</template>
 
<script setup lang="tsx">
import { useForm } from '@cool-vue/crud';
import { Plugins } from '/#/crud';
 
const Form = useForm();
 
function open() {
    Form.value?.open(
        {
            title: '自动聚焦',
 
            items: [
                {
                    label: '昵称',
                    prop: 'nickname',
                    component: {
                        name: 'el-input',
 
                        props: {
                            placeholder: '请输入昵称',
                            clearable: true
                        }
                    }
                },
                {
                    prop: 'age',
                    component: {
                        name: 'el-input-number'
                    },
                    // 默认值,第一次打开有效
                    value: 18
                }
            ]
        },
        [
            // 【很重要】全局已添加该插件
            // Plugins.Form.setFocus('age'), // 指定自动聚焦的字段
            Plugins.Form.setFocus('') // 禁用自动聚焦
        ]
    );
}
</script>