溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

watch監(jiān)聽怎么實現(xiàn)

發(fā)布時間:2022-03-25 10:57:09 來源:億速云 閱讀:235 作者:iii 欄目:web開發(fā)

本篇內(nèi)容主要講解“watch監(jiān)聽怎么實現(xiàn)”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“watch監(jiān)聽怎么實現(xiàn)”吧!

父傳子;父組件通過:purchaserIdProps=“SDEditlForm.sellerId”,子組件用props接受

watch監(jiān)聽(用于回顯)

@focus=“clickWarehouseId”;input輸入框,主要通過foucs事件觸發(fā)接口

if (this.warehouseId) return;判斷如果有值,則不觸發(fā),防止多次掉接口減少性能消耗

disabled: Boolean;:disabled=“disabled”

<template>

  <!--

  value:回顯的倉庫id 

  purchaserIdProps:回顯的主體id 

  <PgWarehouse v-model="SDEditlForm.warehouseId" :purchaserIdProps="SDEditlForm.sellerId"></PgWarehouse>

  -->

  <div>

    <gdb-select v-model="warehouseId" placeholder="請選擇主體" clearable @change="changeWarehouseId" :disabled="disabled" @focus="clickWarehouseId">

      <gdb-option v-for="item in warehouseList" :value="item.id" :key="item.id" :label="item.caption"></gdb-option>

    </gdb-select>

  </div>

</template>

<script>

import '/http/axios'

import $http from '/http/http'

import Api from '/config/api'

export default {

  props: {

    value: {

      type: [String, Number],

      default: ''

    },

    purchaserIdProps: {

      type: [String, Number],

      default: ''

    },

    disabled: Boolean

  },

  data() {

    return {

      warehouseId: '',

      warehouseList: [],

      getWarehouseData: {}

    }

  },

  watch: {

    value(newVal) {

      if (!newVal) {

        this.warehouseId = ''

        this.$emit('input', '')

        this.$emit('select', '')

      } else if (newVal && this.purchaserIdProps) {

        if (this.warehouseId) return

       // 按主體的倉庫回顯

        this.warehouseId = this.value

        this.getWarehouseData.companyId = this.purchaserIdProps

        this.getWarehouseList()

      } else {

        if (this.warehouseId) return

      // 倉庫回顯

        this.warehouseId = this.value

        this.getWarehouseList()

      }

    }

  },

  methods: {

    getWarehouseList() {

      $http

        .get({

          url: Api.getWarehouseList,

          data: this.getWarehouseData

        })

        .then(res => {

          this.warehouseList = res.data.data

        })

    },

    changeWarehouseId() {

      this.$emit('input', this.warehouseId)

      this.$emit('select', this.warehouseId)

    },

    clickWarehouseId() {

      if (this.warehouseId) return

      this.getWarehouseList()

    }

  },

  //生命周期 - 創(chuàng)建完成(訪問當前this實例)

  created() {}

}

</script>

<style lang='scss' scoped>

</style>

到此,相信大家對“watch監(jiān)聽怎么實現(xiàn)”有了更深的了解,不妨來實際操作一番吧!這里是億速云網(wǎng)站,更多相關內(nèi)容可以進入相關頻道進行查詢,關注我們,繼續(xù)學習!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。

AI