vue.js el-select 传多个值

el-select 选择框,选择之后传值,万一要传多个值怎么办,v-model只绑定了一个值。
解决方法: 加入监听事件 @change="getName(temp.communityId)"
以下是vue文件代码

<el-form-item :label="$t('table.communityName')" prop="communityName">
        <el-select
          class="filter-item"
          v-model="temp.communityId"
          :disabled="read"
          :placeholder="$t('table.communityName')"
          @change="getName(temp.communityId)"
        >
          <el-option
            v-for=" item in listcomm"
            :key="item.communityId"
            :label="item.communityName"
            :value="item.communityId"
          ></el-option>
        </el-select>
        <!-- <span v-if="show == false">{{temp.communityName = item.communityName}}</span> -->
      </el-form-item>

以下是js代码,getComm() 获取到列表,getName()循环这个列表,找到与id相同的,取得communityName

getName(val) {
      val = this.temp.communityId
      var array = this.getComm()
      for (let index = 0; index < array.length; index++) {
        const element = array[index].communityId;
        if (element == val) {
          this.temp.communityName = array[index].communityName
        }
      }
      return this.temp.communityName
    },
    getComm() {
      listcommunity().then((response) => {
        this.listcomm = response.data
      })
      return this.listcomm
    },
//这个方法是通过后台接口,直接取得对应的值
// getName(val) {
    //   val = this.temp.communityId
    //   getestatebyid(val).then((response) => {
    //     this.temp.communityName = response.data.communityName
    //   })
    //   return this.temp.communityName
    // },

继续研究下能不能直接传数组

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 这篇笔记主要包含 Vue 2 不同于 Vue 1 或者特有的内容,还有我对于 Vue 1.0 印象不深的内容。关于...
    云之外阅读 5,072评论 0 29
  • Vue 实例 属性和方法 每个 Vue 实例都会代理其 data 对象里所有的属性:var data = { a:...
    云之外阅读 2,233评论 0 6
  • 33、JS中的本地存储 把一些信息存储在当前浏览器指定域下的某一个地方(存储到物理硬盘中)1、不能跨浏览器传输:在...
    萌妹撒阅读 2,096评论 0 2
  • 我是谁,我在哪?啊!头好痛!一个模模糊糊的身影在我面前出现,她说:“檬檬,坚持住。你是天上的天使,这次让你...
    柠檬不萌哟阅读 259评论 0 0
  • 今天中午吃到撑。 这么一说,是不是以为是啥山珍海味?其实,就是咸菜就馍馍。 咸菜,是买的半成品,多加辣椒,大火大油...
    海新帆影阅读 934评论 1 1