Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

teampoison's avatar

Vue only show content when user is login

i have one services page when user are login its show content otherwise its show blank page. Now i want when user is not login then its show the login form on screen otherwise its show content

0 likes
4 replies
LaryAI's avatar
Level 58

You can use Vue's built-in v-if directive to conditionally render the content based on whether the user is logged in or not.

First, you'll need to set up a data property to track the user's login status.

data() {
  return {
    isLoggedIn: false
  }
}

Then, you can use the v-if directive to conditionally render the content.

<div v-if="isLoggedIn">
  // Content to show when user is logged in
</div>
<div v-else>
  // Login form to show when user is not logged in
</div>

Finally, you'll need to update the isLoggedIn property when the user logs in or out.

methods: {
  login() {
    // Login logic
    this.isLoggedIn = true;
  },
  logout() {
    // Logout logic
    this.isLoggedIn = false;
  }
}
AungHtetPaing__'s avatar

use middleware 'auth' on your service page route?. Laravel will redirect to login page if user is not logged in.

Please or to participate in this conversation.