Boa noite, fiz tudo conforme ensinado na aula, mas ao executar o seguinte código:
function recuperarCEP(input){
const cep = input.value.replace(/\D/g, '')
const url = 'https://viacep.com.br/ws/${cep}/json/'
const options = {
method: 'GET',
mode: 'cors',
headers: {
'content-type': 'application/json;charset=utf-8'
}
}
if(!input.validity.patternMismatch && !input.validity.valueMissing){
fetch(url, options).then(
response => response.json()
).then(
data => {
console.log(data)
})
}
}
Está dando estes erros:
Access to fetch at 'https://viacep.com.br/ws/$%7Bcep%7D/json/' from origin 'null' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
validacao.js:192 Uncaught (in promise) TypeError: Failed to fetch at recuperarCEP (validacao.js:192:9) at Object.cep (validacao.js:74:19) at valida (validacao.js:14:34) at HTMLInputElement. (validacao.js:5:9) recuperarCEP @ validacao.js:192 cep @ validacao.js:74 valida @ validacao.js:14 (anônimo) @ validacao.js:5 Promise.then (assíncrono) recuperarCEP @ validacao.js:194 cep @ validacao.js:74 valida @ validacao.js:14 (anônimo) @ validacao.js:5
Gostaria de uma ajuda a enteder onde esta falhando...