MrFox
MrFox
NNuxt
Created by MrFox on 3/26/2025 in #❓・help
Improval of Scrol-Saver
k
34 replies
NNuxt
Created by MrFox on 3/26/2025 in #❓・help
Improval of Scrol-Saver
@kapa.ai without an extra function directly by useUserStore(config.token)
34 replies
NNuxt
Created by MrFox on 3/26/2025 in #❓・help
Improval of Scrol-Saver
@kapa.ai Can I add parameters to the init of useUserStore? Like useUserStore(token:string)
34 replies
NNuxt
Created by MrFox on 3/26/2025 in #❓・help
Improval of Scrol-Saver
@kapa.ai Is this here:
import { defineStore } from 'pinia'
import { ref, computed } from 'vue'

export const useUserStore = defineStore('user', () => {
// State
const user = ref({ name: 'John Doe' })

// Getters (computed properties)
const userName = computed(() => user.value.name)

// Actions (methods)
function updateName(newName) {
user.value.name = newName
}

return {
user,
userName,
updateName
}
})
import { defineStore } from 'pinia'
import { ref, computed } from 'vue'

export const useUserStore = defineStore('user', () => {
// State
const user = ref({ name: 'John Doe' })

// Getters (computed properties)
const userName = computed(() => user.value.name)

// Actions (methods)
function updateName(newName) {
user.value.name = newName
}

return {
user,
userName,
updateName
}
})
Also possible without returning the values?
34 replies
NNuxt
Created by MrFox on 3/26/2025 in #❓・help
Improval of Scrol-Saver
@kapa.ai which methods are therer to create a store using pinia?
34 replies
NNuxt
Created by MrFox on 3/26/2025 in #❓・help
Improval of Scrol-Saver
@kapa.ai Whats the difference between vpage:loading:end and page:finish`?
34 replies
NNuxt
Created by MrFox on 3/26/2025 in #❓・help
Improval of Scrol-Saver
@kapa.ai If I understood right I can use then
nuxtApp.runWithContext(() => {
if (!import.meta.client) return;

onMounted(() => {
const savedPosition = sessionStorage.getItem("sidebarScroll");
const sidebarRef = document.querySelector<HTMLDivElement>("[saveScroll]");
if (savedPosition && sidebarRef) {
sidebarRef.scrollTop = parseInt(savedPosition, 10);
}
});
});
nuxtApp.runWithContext(() => {
if (!import.meta.client) return;

onMounted(() => {
const savedPosition = sessionStorage.getItem("sidebarScroll");
const sidebarRef = document.querySelector<HTMLDivElement>("[saveScroll]");
if (savedPosition && sidebarRef) {
sidebarRef.scrollTop = parseInt(savedPosition, 10);
}
});
});
But this errors:
router.ts:56 [Vue warn]: onMounted is called when there is no active component instance to be associated with. Lifecycle injection APIs can only be used during execution of setup(). If you are using async setup(), make sure to register lifecycle hooks before the first await statement.
34 replies