关于vue.js:elpopover-手动关闭

38次阅读

共计 1157 个字符,预计需要花费 3 分钟才能阅读完成。

咱们晓得 element 提供的 popover 是主动敞开的,那么想手动管制敞开怎么做呢
能够利用 $refs[‘ref_’]提供的 doClose() 办法
比方在表格中,td 项点击弹出 popover

<el-table-column prop=""label=" 出价 "align="center">
          <template slot-scope="scope">
         
            <span>{{parseFloat(scope.row.price).toFixed(2) }} 
              <el-popover
              :ref="'ref_'+scope.row.id"placement="right-start"width="200"trigger="click"
              >
              <div>
                <p> 
                  <input 
                  :id="'price_'+scope.row.id":value="parseFloat(scope.row.price).toFixed(2)"style="width: 100px; height:30px;"/>
                  <el-button type="text" size="mini" @click="setPrice(scope)"> 确定 </el-button>
                  <el-button type="text" size="mini" @click="cancelPrice(scope)"> 勾销 </el-button>
                </p>
                
              </div>
              <i slot="reference" class="el-icon-edit cursor-pointer" v-if="editpriceFlg"></i>
            </el-popover>
              
            </span>

          </template>
        </el-table-column>

js 局部 scope._self.$refs[‘ref_’+id].doClose() 敞开

 cancelPrice(scope){
      let id = scope.row.id
      scope._self.$refs['ref_'+id].doClose()},
    setPrice(scope){
      let id = scope.row.id

      let val = $("#price_"+id).val()
      if(!this.validPrice(val)){$("#price_"+id).val(scope.row.price)
        return
      }
      this.listLoading = true
      request.post('/price',{id: id, price: val}).then((resData)=>{this.$message.info("批改胜利")

      }).finally((_)=>{
        this.listLoading = false
        this.select()
        scope._self.$refs['ref_'+id].doClose()})
    },
    

正文完
 0