tried it with axios
This commit is contained in:
@ -41,6 +41,7 @@
|
||||
<script setup>
|
||||
import { ref } from 'vue';
|
||||
// import LoginService from '../server/loginService.js';
|
||||
import Axios from '../axios.config.js';
|
||||
|
||||
const darkMode = ref(true);
|
||||
</script>
|
||||
@ -53,52 +54,23 @@ export default {
|
||||
const username = document.getElementById('username-input').value;
|
||||
const password = document.getElementById('password-input').value;
|
||||
|
||||
const { data, error } = await useFetch('/api/login', {
|
||||
method: 'post',
|
||||
body: {
|
||||
username: username,
|
||||
password: password
|
||||
}
|
||||
})
|
||||
if (!data.value) {
|
||||
console.log(error.value)
|
||||
} else {
|
||||
console.log(data.value)
|
||||
const requestBody = {
|
||||
username: username,
|
||||
password: password,
|
||||
}
|
||||
// }).then(res => {
|
||||
// const data = res.data.value
|
||||
// const error = res.error.value
|
||||
// if (error) {
|
||||
// // dealing error
|
||||
// // console.log(error)
|
||||
// } else {
|
||||
// console.log(data)
|
||||
// }
|
||||
// }, error => {
|
||||
// console.log('exception...')
|
||||
// console.log(error)
|
||||
// })
|
||||
|
||||
// console.log(data.value)
|
||||
// console.log(error)
|
||||
// }
|
||||
try {
|
||||
let res = await Axios.post('/api/login', requestBody);
|
||||
|
||||
// // const response = await LoginService.login(data);
|
||||
// const { response } = await useFetch('/api/login')
|
||||
// console.log(response)
|
||||
// something to do with the res?
|
||||
console.log(res)
|
||||
|
||||
|
||||
// Axios.post('/api/login', data, {
|
||||
// headers: {
|
||||
// 'Content-Type': 'application/json'
|
||||
// }
|
||||
// })
|
||||
// .then(function (response) {
|
||||
// console.log(response);
|
||||
// })
|
||||
// .catch(function (error) {
|
||||
// console.log(error);
|
||||
// });
|
||||
// sucessfully logged in
|
||||
this.$router.push('/')
|
||||
} catch (err) {
|
||||
// handle the error
|
||||
console.log(err.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user