关于eltable中嵌套elselect问题

请问怎么实现编辑时显示elselect,编辑完毕隐藏elselect

这里用vif点击编辑时,马上可以获取焦点,但是选中elselect中的值不能显示,在vue开发者工具中也没有值,@change事件也获取不到value,

但是改成vshow,以上问题就不存在,但是当点击编辑该cell时,初始获取不到焦点,这样当用户点击该单元格,但是不选中任何东西,该select也不隐藏,需要用户点击获取焦点,在失去焦点才可以隐藏

            <el-table-column label="出货点" width="80" align="center" prop="deliverLocation">
                <template slot-scope="{row,column}">
                    <el-select v-model="row.deliverLocation" v-if="row[column.property + '_isEdit']" filterable
                         @blur="alterData($event,row, column)" @change="alterData($event,row, column)" size="mini" :ref="column.property">
                        <el-option v-for="item in deliverLocationList" :key="item.value" :label="item.text"
                            :value="item.value">
                        </el-option>
                    </el-select>
                    <span v-if="!row[column.property + '_isEdit']">{{ row.deliverLocation }}</span>
                </template>
            </el-table-column>
        //编辑单元格事件更新
        editName(row, column) {
            if (!column.property + '_isEdit') {
                this.$set(row, column.property + '_isEdit', true);
            }
            row[column.property + '_isEdit'] = true;
            this.$nextTick(() => {

                //判断该单元格是否放置元素组件
                if (typeof this.$refs[column.property] == 'undefined') return;
                //通过对元素设置特殊属性x来定义是否能够获取焦点
                //if (this.$refs[column.property].$attrs.x) {
                console.log(this.$refs[column.property]);
                this.$refs[column.property] && this.$refs[column.property].focus()
                //}
            })

        },
        //表格触发事件
        alterData(event,row, column) {
            console.log(event,row,column);
            this.$nextTick(() => {
                row[column.property + '_isEdit'] = false;
            })
        },

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
`el-select` 是 Element UI 提供的一个下拉选择组件,而 `el-table` 是一个用于展示表格数据的组件。要实现 `el-select` 自定义插槽(Slot)嵌套 `el-table`,主要是为了动态地根据选的值在下拉选项显示相关的表格数据。以下是一个基本的示例: ```html <template> <el-select v-model="selectedValue" placeholder="请选择"> <template #default> <!-- 下拉选项 --> <el-option v-for="(item, index) in options" :key="index" :label="item.label" :value="item.value" @click="showTable(item)" ></el-option> </template> <template #empty> <span>无匹配数据</span> </template> </el-select> <!-- 使用 slot: table 插槽来展示表格内容 --> <template v-if="tableData"> <el-table :data="tableData"> <el-table-column prop="prop1" label="列1"></el-table-column> <!-- 添加更多列... --> <template slot="table"> <!-- 这里使用 slot-content 或者 slot="default" 替换 --> <slot name="table">表内容将在这里根据 selectedValue 的值动态渲染</slot> </template> </el-table> </template> </template> <script> export default { data() { return { selectedValue: '', options: [ { value: 'option1', label: '选项1' }, { value: 'option2', label: '选项2' }, // 更多选项... ], tableData: null, }; }, methods: { showTable(item) { this.tableData = item.data; // 假设 item 数据包含表格数据 }, }, }; </script> ``` 在这个例子,当用户选择 `el-select` 的某个选项时,`showTable` 方法会被调用,更新 `tableData`。然后在 `el-table` 的 `table` 插槽,你可以根据 `selectedValue` 的值动态渲染表格内容。 相关问题: 1. 在这个例子,`template #default` 和 `template #empty` 分别代表什么? 2. 如何确保表格数据的结构与选项的数据结构匹配? 3. 如何处理 `selectedValue` 变化时,`tableData` 更新但表格不刷新的情况?

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值