Click Event is not working

Hello dear people... i wanted to make a simple click event for a button. Strangely it doesnt work and I tried out some things but I dont get it to work. Im pretty new in vue and nuxt to I would be happy to get some help :) Code:
<script setup lang="ts">
import {PlayFab} from "playfab-sdk";
import {PlayFabClient} from "playfab-sdk";

const config = useRuntimeConfig();


const registerRequest = {
TitleId: PlayFab.settings.titleId,
Password: 'djaksdjaskldj22',
RequireBothUsernameAndEmail: true,
Username: 'ZeroOne'
}

function registerUser() {
console.log('registerUser');
PlayFab.settings.titleId = config.playFab_titleId;
PlayFabClient.RegisterPlayFabUser(registerRequest, LoginCall)
}

function LoginCall() {
console.log("Registration successful");
}
</script>

<template>
<button v-on:click="LoginCall">Register</button>
</template>

<style scoped>

</style>
<script setup lang="ts">
import {PlayFab} from "playfab-sdk";
import {PlayFabClient} from "playfab-sdk";

const config = useRuntimeConfig();


const registerRequest = {
TitleId: PlayFab.settings.titleId,
Password: 'djaksdjaskldj22',
RequireBothUsernameAndEmail: true,
Username: 'ZeroOne'
}

function registerUser() {
console.log('registerUser');
PlayFab.settings.titleId = config.playFab_titleId;
PlayFabClient.RegisterPlayFabUser(registerRequest, LoginCall)
}

function LoginCall() {
console.log("Registration successful");
}
</script>

<template>
<button v-on:click="LoginCall">Register</button>
</template>

<style scoped>

</style>
I hope to get some help :)
49 Replies
kapa.ai
kapa.ai3w ago
Hi @フェリックス. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- I see the issue with your click event. The button is correctly set up with v-on:click="LoginCall", but you're trying to call the LoginCall function when the button is clicked, while your actual registration logic is in the registerUser function. Here's how you can fix it:
<script setup lang="ts">
import {PlayFab} from "playfab-sdk";
import {PlayFabClient} from "playfab-sdk";

const config = useRuntimeConfig();

const registerRequest = {
TitleId: PlayFab.settings.titleId,
Password: 'djaksdjaskldj22',
RequireBothUsernameAndEmail: true,
Username: 'ZeroOne'
}

function registerUser() {
console.log('registerUser');
PlayFab.settings.titleId = config.playFab_titleId;
PlayFabClient.RegisterPlayFabUser(registerRequest, LoginCall)
}

function LoginCall() {
console.log("Registration successful");
}
</script>

<template>
<button @click="registerUser">Register</button>
</template>
<script setup lang="ts">
import {PlayFab} from "playfab-sdk";
import {PlayFabClient} from "playfab-sdk";

const config = useRuntimeConfig();

const registerRequest = {
TitleId: PlayFab.settings.titleId,
Password: 'djaksdjaskldj22',
RequireBothUsernameAndEmail: true,
Username: 'ZeroOne'
}

function registerUser() {
console.log('registerUser');
PlayFab.settings.titleId = config.playFab_titleId;
PlayFabClient.RegisterPlayFabUser(registerRequest, LoginCall)
}

function LoginCall() {
console.log("Registration successful");
}
</script>

<template>
<button @click="registerUser">Register</button>
</template>
I've made two changes: 1. Changed the click handler to call registerUser instead of LoginCall since that's the function that initiates the registration process 2. Used the shorthand @click instead of v-on:click (both work the same way, but @click is more commonly used in Vue) In Nuxt/Vue, the click event should work as long as you're calling the correct function. The @click directive is the standard way to handle click events in Vue templates. If you're still having issues, make sure that: - Your component is properly mounted - There are no console errors - The PlayFab SDK is properly imported and initialized ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3w ago
<@781613262097219605> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Omnislash
Omnislash3w ago
Hello, Looks ok to me, any warning/error in the browser console ?
フェリックス
Nope nothing thats what confuses me
Omnislash
Omnislash3w ago
Indeed.... What if you : - Add a console.log directly in the script tag - replace the function call in the click by a console log Just to be extra sure, I would comment everything else in the script.
フェリックス
Does it work like that: <button @click="console.log('Test')">Tester</button> ? The console.log directly in the script tag works fine
Omnislash
Omnislash3w ago
It should
フェリックス
<script setup lang="ts"> import rButton from '../components/registerButton.vue' const testing = () => { console.log('testing') } </script> <template> <form id="loginForm"> <label for="username">Username or Email:</label> <input type="text" id="username" name="username" required> <label for="password">Password:</label> <input type="password" id="password" name="password" required> <button type="submit">Login</button> <button type="reset">Reset</button> <p><a href="#">Forgot Password?</a></p> <p><a href="#">Register</a></p> </form> <rButton /> <button @click="testing">Tester</button> </template> <style scoped> </style>
Omnislash
Omnislash3w ago
With the rest of the script commented ?
フェリックス
i also had it with function testing() {} etc. also not working with the console log directly behind the @click is also not working
Omnislash
Omnislash3w ago
Hum.... Is the project on github, stackblitz or something ?
フェリックス
GitHub
GitHub - ZeroOneJP/nuxt-playfab-test
Contribute to ZeroOneJP/nuxt-playfab-test development by creating an account on GitHub.
フェリックス
sure i also tried it with components, so you going to find a button component under the components folder
Omnislash
Omnislash3w ago
Nice, let me have a little look Can I just pull install and launch or is there third services dependencies?
フェリックス
There will be the playfab sdk but its only implemented in the button component sure you can pull Playfab is a videogame backend from Microsoft so dont worry c:
Omnislash
Omnislash3w ago
no problem ^^ A few things while it's launching You normally don't need to import your components, they are auto imported https://nuxt.com/docs/guide/directory-structure/components
フェリックス
ah okay
Omnislash
Omnislash3w ago
You can even put them in subfolder, it will by default be accessible with the folder name, you should have a read at the basic folders documentation 🙂 from some other reasons, you should have one root and one root only in each template (you'll understand if you read about pages, layouts, transitions and Nuxt UI) So you should wrap your template content around <section> or <div> or anything is appropriate at the time
フェリックス
ah okay good to know thanks
Omnislash
Omnislash3w ago
Soooooo all your buttons work for me ^^"
フェリックス
ahhh okayy alright, so is this why it dont register the events? but with your changes right? the div etc.
Omnislash
Omnislash3w ago
(don't mind the warnings it's my browser)
No description
Omnislash
Omnislash3w ago
nop, that's for other stuff, I just npm install then npm run dev.... and it works what browser are you using ? is it up to date ?
フェリックス
mainly safari but also with chrome and it didnt work
Omnislash
Omnislash3w ago
maybe try a brand new fresh pull, npm install then npm run dev ?
フェリックス
I´ll try one moment
Omnislash
Omnislash3w ago
if not... I have seriously no idea ^^", my only guess would be outdated browser or anything browser related or maybe the node or npm version ?
フェリックス
I´m on my mac with Jetbrains Webstorm maybe thats a problem? npm = 10.9.1 and node = v22.11.0
Omnislash
Omnislash3w ago
hum :/ well I don't use either so I can't tell you if there is any thing to look for, but I've seen people using it so it shouldn't
フェリックス
let me switch to my windows pc and try it there
Omnislash
Omnislash3w ago
sure you can even create a https://stackblitz.com/ account and import the project (I think you can import, or pull, or juste quickly copy your files) and try from there too. Always an easy way to see if it's environment related
フェリックス
I recently tried it in GitHub code spaces and it did not even started correctly haha
Omnislash
Omnislash3w ago
I didn't even know github was doing something like that too XD In stackblitz you can directly create a nuxt 3 project, so you usually don't have any setup issue
フェリックス
dont even have node installed on windows xD i´ll try stackblitz
Omnislash
Omnislash3w ago
ahaha
Omnislash
Omnislash3w ago
that's the best to get very easy set up with node on windows : https://volta.sh/
Omnislash
Omnislash3w ago
with a single command line you can install any version on any project I know there is similar things for mac (no idea if volta works on mac)
フェリックス
man still now working
Omnislash
Omnislash3w ago
wow :/ no error ? not even in the npm install ?
フェリックス
ouhh never heard about that sounds nice https://stackblitz.com/~/github.com/ZeroOneJP/nuxt-playfab-test can you join with that? no error
Omnislash
Omnislash3w ago
probably, it's booting
フェリックス
alright
Omnislash
Omnislash3w ago
it works for me ^^" just to make it very utterly sure : you don't look at the stacklitz terminal or output or else. You open the browser console with ctrl+shift+i and go in the console from there right ? because that's clearly mystic that your console.log are working for me and not for you on stackblitz ^^"
フェリックス
my goooooooooooooooooooooooooooooooood i looked at the terminal the whole time, i just thought about that, i should end my career
Omnislash
Omnislash3w ago
ahaha it happens :), at least it's solved XD
フェリックス
still thank you so much for your amazing help and trying :)
Omnislash
Omnislash3w ago
no problem, discovering vue and nuxt was a wonderful experience for me, I hope you'll enjoy it
フェリックス
yes im really excited for it, im building videogames with unreal engine 5 and c++, and we want to make the website with nuxt for it so ill keep pushing through :)
Omnislash
Omnislash3w ago
Good luck, the help is there if needed ^^

Did you find this page helpful?