VUE联动下拉选择框

在这里插入图片描述

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .main {
            width: 500px;
            margin: 50px auto;
            padding: 15px;
            background-color: antiquewhite;
        }
        .item>p {
            display: inline-block;
            margin-right: 10px;
            width: 100px;
            text-align: right;
        }
        .item>select {
            min-width: 100px;
        }
    </style>
</head>
<body>
    <div class="main">

        <div class="item">
            <p>项目名称</p>
            <select v-model="entryValue" @change="entryChange">
                <option v-for="item in mapData" :key="item.entryId" :value="item.entryId" :lable="item.entry">
                    {{item.entry}}
                </option>
            </select>
        </div>
        
        <div class="item">
            <p>标段名称</p>
            <select v-model="sectionValue" @change="sectionChange">
                <option v-for="item in sectionOptions" :value="item.sectionId" :lable="item.section">
                    {{item.section}}
                </option>
            </select>
        </div>

        <div class="item">
            <p>参与安全员</p>
            <select v-model="personValue">
                <option v-for="item in personOptions" :value="item.personId" :lable="item.person">
                    {{item.person}}
                </option>
            </select>
        </div>
        
        <p>选中的项目名称ID为:{{entryValue}},标段名称ID为:{{sectionValue}},参与安全员ID为:{{personValue}}</p>
        <h3>选中的项目名称entryValue: {{entryValue}}</h3>

    </div>
    
    <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.11/vue.js"></script>
    <script>
        var vueMain = new Vue({
            el: '.main',
            data: {
                mapData: [
                    {
                        entryId: '1',
                        entry: '项目1',
                        sectionArr: [
                            {
                                sectionId: '1-1',
                                section: '项目1标段1',
                                personArr: [
                                    {
                                        personId: '1-1-1',
                                        person: '项目1标段1安全员1'
                                    },
                                    {
                                        personId: '1-1-2',
                                        person: '项目1标段1安全员2'
                                    },
                                    {
                                        personId: '1-1-3',
                                        person: '项目1标段1安全员3'
                                    },
                                ]
                            },
                            {
                                sectionId: '1-2',
                                section: '项目1标段2',
                                personArr: [
                                    {
                                        personId: '1-2-1',
                                        person: '项目1标段2安全员1'
                                    },
                                    {
                                        personId: '1-2-2',
                                        person: '项目1标段2安全员2'
                                    },
                                    {
                                        personId: '1-2-3',
                                        person: '项目1标段2安全员3'
                                    },
                                ]
                            }
                        ]
                    },
                    {
                        entryId: '2',
                        entry: '项目2',
                        sectionArr: [
                            {
                                sectionId: '2-1',
                                section: '项目2标段1',
                                personArr: [
                                    {
                                        personId: '2-1-1',
                                        person: '项目2标段1安全员1'
                                    },
                                    {
                                        personId: '2-1-2',
                                        person: '项目2标段1安全员2'
                                    },
                                    {
                                        personId: '2-1-3',
                                        person: '项目2标段1安全员3'
                                    },
                                ]
                            },
                            {
                                sectionId: '2-2',
                                section: '项目2标段2',
                                personArr: [
                                    {
                                        personId: '2-2-1',
                                        person: '项目2标段2安全员1'
                                    },
                                    {
                                        personId: '2-2-2',
                                        person: '项目2标段2安全员2'
                                    },
                                    {
                                        personId: '2-2-3',
                                        person: '项目2标段2安全员3'
                                    },
                                ]
                            }
                        ]
                    }
                ],
                // 标段下拉项数组
                sectionOptions: [],
                // 安全员下拉项数组
                personOptions: [],
                // 项目选中值
                entryValue: '',
                // 标段选中值
                sectionValue: '',
                // 安全员选中值
                personValue: ''
            },
            methods: {
                entryChange() {
                    const item = this.mapData.find(item => item.entryId == this.entryValue)
                    this.sectionOptions = item.sectionArr
                    this.sectionValue = ''
                    this.personValue = ''
                },
                sectionChange() {
                    const item = this.sectionOptions.find(item => item.sectionId == this.sectionValue)
                    this.personOptions = item.personArr
                    this.personValue = ''
                }
            }
        })
    </script>
</body>
</html>
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值