-
Hello, I am playing around with AlpineJS, pinecone router and try to create a SPA using https://fakerapi.it with books-api. I create an books object and several views (list, edit, new). But the virtual pages do not have access to my global object (books).
How can I use pinecone router together with other alpinejs object? Also also tried Alpine.Store() and $store.books.books[0].id, etc. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You're defining the store wrong, second argument should be an object not a function. please refer to the docs document.addEventListener('alpine:init', () => {
Alpine.store('books', {
books: [],
message: 'Hello',
async init() {
// this.books = this.getBooks();
this.books = ['one', 'two'];
},
});
}); |
Beta Was this translation helpful? Give feedback.
Thanks for reporting and sorry for the inconvenience. I don't know how this passed me, template elements should be initialized with the proper context, includingthis.$store
, I'm looking into itYou're defining the store wrong, second argument should be an object not a function. please refer to the docs