Question:
Why logged user object is all strings in Vuejs and Laravel 10?

To extract just the user name from the JSON string you've stored in the meta tag in your Laravel view and pass it to your Vue.js component, you can follow these steps:


  1. In your Laravel app.blade.php, pass only the user name as a separate meta tag:

<meta name="user_name" content="{{ Auth::user()->name }}">


2. In your Vue.js index.vue component, extract the user name from the meta tag:

<template>

  <div>

    {{ loggedUserName }}

  </div>

</template>


<script setup>

import { ref, onMounted } from 'vue';


const loggedUserName = ref('');


onMounted(() => {

  const metaTag = document.querySelector("meta[name='user_name']");

  if (metaTag) {

    loggedUserName.value = metaTag.getAttribute('content');

  }

});

</script>


With these changes, you are passing only the user name from Laravel to Vue.js, and in your Vue component, you extract and display just the user name.


Suggested blogs:

>Fix ASP.NET Core Model Binding Not Working issue.

>How to create a zip file and return it to client for download?

>How to Group large number of data based on CreatedDate(DateTime)?

>Issues converting ASPX Web app from .net 3.5 to 4.8.1

>Fix Asp.net issue: AjaxControlToolkit FileUpload not working

>Using Fetch in JS to call a server-side method (ASP.NET)

>Need input on Standalone SSRS SQL Server 2016 Report Builder

>How to fix: View not found even though it exists issue?

>Fixing C# sync over async implementations

>How to optimize getting multiple documents 'one by one' in Firestore?

>How to use/set up Node Express sessions?


Ritu Singh

Ritu Singh

Submit
0 Answers