I'm trying to work with modules, but when I try to import and use the method I receive the error - reference error onLogin is not defined, what can I be doing wrong?
- LoginController.js
import Api from "/src/Utils/Api.js";
export default async function onLogin() {
try {
debugger
document.getElementById("loading").style.visibility = 'visible';
var usuario = {
snome: document.getElementById("EdtUsuario").value,
ssenha: document.getElementById("EdtSenha").value
};
let retorno = await Api.post('/Login/login/', usuario);
console.log(retorno);
} catch (error) {
document.getElementById("loading").style.visibility = 'hidden';
console.log(error);
}
}
- Import in View
<script type="module"> import onLogin from '/src/Controller/LoginController.js'</script>
The Method onLogin is called on event onClick
<button onclick="onLogin()" type="submit" class="botaowidth100">Entrar</button >