用vue做下拉框设置代码

表达1

<el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="110px">
      <el-form-item label="客户名称" prop="clientName">
        <el-select  v-model="queryParams.clientName" placeholder="请选择客户名称" clearable size="small" >
          <el-option
            v-for="dict in clientnameOptions"
            :key="dict.id"
            :label="dict.clientName"        
            :value="dict.id+''"
          />
       </el-select>
      </el-form-item>
<el-table v-loading="loading" :data="contractList" @selection-change="handleSelectionChange" style="width: 200%">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="客户名称" align="center" prop="cilentName":formatter="cilentNameFormat" width="100">
      </el-table-column>
</el-table>      

这里是引用另外一个表的数据:basics表中的

import {listBasics} from "@/api/system/basics";
created() {
  listBasics({pageSize: 999999}).then(response => {
      this.clientNameOptions = response.rows;
    })
  }  
 methods: {
 clientNameFormat(row){
  let kh= this.clientNameOptions.filter(p => p.id+'' === row.clientName).pop();
        if (typeof kh === "undefined") return "";
        return yz.clientName;
    }
 }

表达二

   <el-form-item label="数量单位" prop="numberunit">
          <el-select v-model="form.numberUnit" placeholder="请选择数量单位">
            <el-option
              v-for="dict in numberUnitOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
  <el-table-column label=" 数量单位" align="center" prop="numberUnit" :formatter="numberUnitFormat" width="120" />
 created() {
    this.getDicts("numberUnit").then(response => {
      this.numberUnitOptions = response.data;
    });
 }
 numberUnitFormat(row, column) {
      return this.selectDictLabel(this.numberUnitOptions, row.numberUnit);
    },

:key=“dict.dictValue”
:label=“dict.dictLabel”
:value=“dict.dictValue”
这里不是很明白,这是利用框架代码生成的

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当然可以,下面是一个简单的Vue下拉框组件代码: ```html <template> <div class="select-wrapper"> <div class="select" :class="{active: isOpen}" @click="toggle"> <div class="selected-option">{{ selectedOption }}</div> <i class="fas fa-chevron-down"></i> </div> <ul class="options" v-show="isOpen"> <li v-for="(option, index) in options" :key="index" @click="select(option)"> {{ option }} </li> </ul> </div> </template> <script> export default { props: { options: { type: Array, required: true }, defaultOption: { type: String, default: '' } }, data() { return { isOpen: false, selectedOption: this.defaultOption } }, methods: { toggle() { this.isOpen = !this.isOpen }, select(option) { this.selectedOption = option this.isOpen = false } } } </script> <style> .select-wrapper { position: relative; display: inline-block; } .select { border: 1px solid gray; padding: 10px; display: flex; align-items: center; cursor: pointer; } .select.active { border-bottom-left-radius: 0; border-bottom-right-radius: 0; } .selected-option { flex: 1; } .options { position: absolute; top: 100%; left: 0; border: 1px solid gray; border-top: none; list-style: none; padding: 0; margin: 0; background-color: white; border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; max-height: 200px; overflow-y: auto; } .options li { padding: 10px; cursor: pointer; } .options li:hover { background-color: #f1f1f1; } </style> ``` 使用方法: ```html <template> <div> <my-select :options="colors" default-option="Select a color"></my-select> </div> </template> <script> import MySelect from './MySelect.vue' export default { components: { MySelect }, data() { return { colors: ['Red', 'Blue', 'Green', 'Yellow'] } } } </script> ``` 这个组件会渲染一个类似下拉框的UI,其中`options`是下拉框中的选项,`defaultOption`是默认选项。当用户点击下拉框时,会显示下拉框的选项列表,用户可以选择其中的一个选项。选择完成后,下拉框会显示所选的选项。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值