How to implement watch snooping
This article mainly explains "how to achieve watch snooping". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "how to achieve watch snooping"!
The parent passes on the child; the parent component passes through: purchaserIdProps= "SDEditlForm.sellerId", and the child component is accepted by props.
Watch snooping (for echo)
@ focus= "clickWarehouseId"; input input box, mainly through the foucs event trigger interface
If (this.warehouseId) return; determines that if there is a value, it will not trigger, preventing multiple interface drops and reducing performance consumption.
Disabled: Boolean;:disabled= "disabled"
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
/ / Warehouse echo by subject
This.warehouseId = this.value
This.getWarehouseData.companyId = this.purchaserIdProps
This.getWarehouseList ()
} else {
If (this.warehouseId) return
/ / Warehouse echo
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 ()
}
}
/ / Lifecycle-created (access the current this instance)
Created () {}
}
At this point, I believe you have a deeper understanding of "how to achieve watch snooping". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!