el-input展示多个值

本文展示了如何在Vue.js前端应用中使用el-input组件来显示多个值,如AAA, BBB, CCC。内容涉及如何创建一个下拉列表,用户可以从中选择并回填到输入框中,实现主推款商品选择的功能。" 129787713,5891101,Python视音频处理:Scikit-Video库详解,"['Python', '开发语言', '人工智能', '视音频处理']

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

以下是表格效果图AAA,BBB,CCC是测试数据,本来应该展示TA20301818ASHLR,

在这里插入图片描述

主推款商品选择输入框触发下拉列表,再勾选回填。
在这里插入图片描述
在这里插入图片描述

 //1.表单输入框触发下拉列表事件
 <el-form-item label="主推商品选择" prop="spmc">
          <el-input
            v-model="dataForm2.spmc"
            placeholder="请输入"
            clearable
            @focus="getPsndoc()"
          ></el-input>
</el-form-item>

el-button:确定按钮

2.多选列表
 <el-table
        :row-key="
          (row) => {
            return row.id
          }
        "
        :data="psndocList"
        ref="multipleTable"
        @selection-change="handleSelectionChange"
      >
        <el-table-column
          type="selection"
          width="55"
          label="选择"
          reserve-selection=true
        >
 </el-table>

data:{
	psndocList: []//整个列表的数据
	multipleSelection:[], //勾选的数据
	sids:[],//新增时勾选的数据的id情况二需要传给后端
	ztkids:[]//编辑时勾选数据的id情况二

},

 watch: {
    dialogFormVisible(val) {
      if (!val) {
        this.input_ry = ''
      }
    },

    //新增时弹窗默认不回填
    salaryShow2(val) {
      if (!val) {
        this.dataForm2.id = ''
        for (var key in this.dataForm2) {
          this.dataForm2[key] = ''
        }
        this.$refs['dataForm2'].clearValidate()
      }
    },
  },

methods:{
		getPsndoc(){
			//1.此方法通过接口调用返回数据并且将数组在el-table中展示
 			this.psndocList = res.data.data
			
			 this.$nextTick(() => {
              this.ztkids.forEach((key) => { //编辑时默认回显多选的id
                this.psndocList.forEach((row) => { //列表所有数据和默认选中的对比
                  if (row.id == key) {
                    this.$refs.multipleTable.toggleRowSelection(row, true) //勾选回显
                  }
                })
              })
            })
 		},
 		
 		//2.获取默认选取表格选中的值
   		handleSelectionChange(val) {
      			this.multipleSelection = val
      			console.log(this.multipleSelection)
    	},
    	//3.el-table表格数据有多行需要做分页, el-table必须加 :row-key 和el-table-column
    	//必须加reserve-selection=true才能保留上一页的数据
    	
 		//4.行编辑按钮
   		updateBtn(row) {
			//4.编辑按钮表单回显文本 多选之后需要回显到输入框
 	 		this.dataForm2.spmc = this.multipleSelection.map((el) => el.spmc).join(',') //遍历数组中需要展示的值
			
			 //id回显的数组编辑时遍历出的数组id
     		this.ztkids = row.jcZtlbZtkVoList.map((el) => el.ztkId) //编辑时
      			console.log(this.ztkids)
		},

		//确定提交,传后端需要的是勾选的id,有多个就返回多个放入数组ids

		dataFormSubmit2(dataForm2) {
      	this.$refs[dataForm2].validate((valid) => {
        for (var i = 0; i < this.multipleSelection.length; i++) {
          if (
            this.multipleSelection[i] != undefined &&
            this.multipleSelection.length > 0
          ) {
            this.sids= this.multipleSelection.map((item) => item.id)   //新增时
          } else {
            this.sids= this.ztkids
          }
        }
         if (valid) {
			//参数
          let params = {
            ztkid: this.sids,
            ......
            }

		//调用接口传params参数........
		this.$http.post(this.$api.addJczt, params).then(({ data }) => {
		......
		})
 }



二、例举el-table某列遍历多个值
 dataList: [
        {
          id: 1,
          spdm: '4111',
          spmc: [
            {
              id: 1,
              name: 'AAAAA',
            },
            {
              id: 2,
              name: 'BBBB',
            },
            {
              id: 3,
              name: 'CCCC',
            },
          ],
        },
      ],
<el-table :data="dataList">
 <el-table-column
        prop="spmc"
        label="商品名称"
        header-align="center"
        align="center"
      >
  <template slot-scope="scope">
    <span v-for="(item, index) in scope.row.spmc" :key="index">
            {{ item.name }}
  </span>
</template>
</el-table-column>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值