login en pinia
This commit is contained in:
@@ -7,35 +7,8 @@
|
||||
<script setup>
|
||||
import { ref, onMounted } from "vue";
|
||||
import { useListaStore } from "../stores/lista.js";
|
||||
|
||||
const listaStore = useListaStore();
|
||||
|
||||
const resultList = ref("");
|
||||
|
||||
listaStore.counter = 9;
|
||||
console.log(listaStore.counter);
|
||||
console.log(listaStore.doubleCount());
|
||||
console.log(listaStore.counter);
|
||||
listaStore.increment();
|
||||
console.log(listaStore.counter);
|
||||
|
||||
// after the above you can also access the auth data from the authStore
|
||||
// console.log(pb.authStore.isValid);
|
||||
// console.log(pb.authStore.token);
|
||||
// console.log(pb.authStore.model.id);
|
||||
// // console.log(authData);
|
||||
//
|
||||
// pb.collection("lista")
|
||||
// .getList(1, 50)
|
||||
// .then((result) => {
|
||||
// // success...
|
||||
// console.log("Result:", result);
|
||||
// resultList.value = result;
|
||||
// })
|
||||
// .catch((error) => {
|
||||
// // error...
|
||||
// console.log("Error:", error);
|
||||
// });
|
||||
|
||||
// "logout" the last authenticated account
|
||||
//pb.authStore.clear();
|
||||
listaStore.login();
|
||||
</script>
|
||||
|
||||
47
src/stores/lista.js
Normal file
47
src/stores/lista.js
Normal file
@@ -0,0 +1,47 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { ref } from "vue";
|
||||
import PocketBase from "pocketbase";
|
||||
|
||||
export const useListaStore = defineStore("lista", () => {
|
||||
const pb = new PocketBase("https://pocketbase.clonbg.es");
|
||||
const authData = ref("");
|
||||
function login() {
|
||||
authData.value = pb
|
||||
.collection("users")
|
||||
.authWithPassword("clonbg", "m4nu3lm4nu3l")
|
||||
.then((r) => {
|
||||
console.log("logueado");
|
||||
})
|
||||
.catch((e) => {
|
||||
console.log("error");
|
||||
});
|
||||
}
|
||||
return { pb, authData, login };
|
||||
});
|
||||
|
||||
/*
|
||||
--- Pinia
|
||||
|
||||
export const useListaStore = defineStore("lista", () => {
|
||||
const counter = ref(3);
|
||||
function increment() {
|
||||
counter.value++;
|
||||
}
|
||||
function doubleCount() {
|
||||
return counter.value * 2;
|
||||
}
|
||||
return { counter, increment, doubleCount };
|
||||
});
|
||||
|
||||
|
||||
--- vue
|
||||
|
||||
listaStore.counter = 9;
|
||||
console.log(listaStore.counter);
|
||||
console.log(listaStore.doubleCount());
|
||||
console.log(listaStore.counter);
|
||||
listaStore.increment();
|
||||
console.log(listaStore.counter);
|
||||
|
||||
|
||||
*/
|
||||
Reference in New Issue
Block a user