BobSty
BobSty
NNuxt
Created by BobSty on 4/28/2024 in #❓・help
Page wont redirect after parameter change
No description
36 replies
NNuxt
Created by BobSty on 4/24/2024 in #❓・help
Event is triggered twice
I have a eventBus.js class which looks like this:
import emitter from 'tiny-emitter/instance'

export default {
$on: (...args) => emitter.on(...args),
$once: (...args) => emitter.once(...args),
$off: (...args) => emitter.off(...args),
$emit: (...args) => emitter.emit(...args)
}
import emitter from 'tiny-emitter/instance'

export default {
$on: (...args) => emitter.on(...args),
$once: (...args) => emitter.once(...args),
$off: (...args) => emitter.off(...args),
$emit: (...args) => emitter.emit(...args)
}
I also have the parent vue component from where I trigger the event, it looks like this:
<template>
<button id="username-button" @click="insertText('{username}')">Username</button>
</template>

<script>
import eventBus from '/eventBus';

export default {
methods: {
insertText(keyword) {
eventBus.$emit('insertKeywords', keyword);
}
}
}
</script>
<template>
<button id="username-button" @click="insertText('{username}')">Username</button>
</template>

<script>
import eventBus from '/eventBus';

export default {
methods: {
insertText(keyword) {
eventBus.$emit('insertKeywords', keyword);
}
}
}
</script>
And I have the child vue component where I listen to the event:
<script>
import eventBus from '/eventBus'
export default {
created() {
eventBus.$on('insertKeywords', (keyword) => {
console.log('why is this called twice???')
})
},
destroyed() {
eventBus.$off('insertKeywords')
}
};
</script>
<script>
import eventBus from '/eventBus'
export default {
created() {
eventBus.$on('insertKeywords', (keyword) => {
console.log('why is this called twice???')
})
},
destroyed() {
eventBus.$off('insertKeywords')
}
};
</script>
So far so good, but the event is always triggered twice for some reason. I checked the Function which is emitting the event, the function is only called once. But for some reason eventBus.$on(...) is always called twice, no matter how often I reload or navigate through pages. Does anyone know why this is happening?
2 replies
NNuxt
Created by BobSty on 4/4/2024 in #❓・help
Auth with Discord
So im trying to set up auth for discord but as soon as I add the modules '@nuxtjs/axios' and '@nuxtjs/auth-next' into my nuxt.config.ts this error occurs Cannot read properties of undefined (reading 'options') on npm install nuxt.config.ts
export default ({
devtools: { enabled: true },
components: true,
modules: [
'@nuxtjs/axios',
'@nuxtjs/auth-next'
],
css: ['~/css/global.css'],
auth: {
strategies: {
discord: {
clientId: '',
clientSecret: ''

}
}
}
})
export default ({
devtools: { enabled: true },
components: true,
modules: [
'@nuxtjs/axios',
'@nuxtjs/auth-next'
],
css: ['~/css/global.css'],
auth: {
strategies: {
discord: {
clientId: '',
clientSecret: ''

}
}
}
})
I've read somewhere that modules work different in nuxt v3 but I somehow cant figure it out. I have following packages:
"@nuxt/kit": "^3.11.1",
"@nuxtjs/auth-next": "^5.0.0-1667386184.dfbbb54",
"@nuxtjs/axios": "^5.13.6",
"nuxt": "^3.11.1",
"ts-essentials": "^9.4.1",
"vue": "^3.4.21",
"vue-meta": "^2.4.0",
"vue-router": "^4.3.0",
"vuex": "^4.1.0"
"@nuxt/kit": "^3.11.1",
"@nuxtjs/auth-next": "^5.0.0-1667386184.dfbbb54",
"@nuxtjs/axios": "^5.13.6",
"nuxt": "^3.11.1",
"ts-essentials": "^9.4.1",
"vue": "^3.4.21",
"vue-meta": "^2.4.0",
"vue-router": "^4.3.0",
"vuex": "^4.1.0"
Does anyone have a example by chance on how to do it the right way?
5 replies