-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
30 lines (26 loc) · 990 Bytes
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// CAPTURA DOS INPUTS E BUTTON DO HTML
const searchCep = document.querySelector('.searchCep')
const buttonSearch = document.querySelector('.buttonSearch')
const street = document.querySelector('.street')
const distric = document.querySelector('.distric')
const city = document.querySelector('.city')
const ufEstado = document.querySelector('.uf')
const number = document.querySelector('.number')
const complement = document.querySelector('.complement')
// INTREGRAÇÃO COM A API VIACEP
const searchApi = async (cepNumber) => {
const response = await axios.get(
`https://viacep.com.br/ws/${cepNumber}/json/`
)
const { bairro, uf, logradouro, localidade, complemento } = response.data
street.value = logradouro
distric.value = bairro
city.value = localidade
ufEstado.value = uf
complement.value = complemento
}
// CRIAÇÃO DE EVENTO DE ENVIO PARA O BOTÃO
buttonSearch.addEventListener('submit', (event) => {
event.preventDefault()
searchApi(searchCep.value)
})