How to load dynamic images from url in Nuxt3?
P粉236743689
P粉236743689 2023-08-30 10:17:55
0
1
613
<p>I have a nuxt 3 component that cannot load a dynamic image that I get from a specific URL (auth0 image). </p> <p>My template looks like this:</p> <pre class="brush:php;toolbar:false;"><template> <img class="h-28 w-28 rounded-full border-4 border-black bg-gray-300" :src="image" alt=" " /> <p> {{{name}} {{image}} </p> </template></pre> <p>My script is set up as follows:</p> <pre class="brush:php;toolbar:false;"><script setup> import { useAuth0 } from '@auth0/auth0-vue'; let auth0 = process.client ? useAuth0() : undefined; let name = ref(''); let image = ref(''); //check user authentication state and set name and image if(auth0?.isAuthenticated){ name.value = auth0?.user.value.nickname; //image url: https://.... image.value = auth0?.user?.value.picture; } </script></pre> <p>The name and image appear in the paragraph, but the image url does not exist in the src attribute, so the image does not appear. When I go back and type something in VSCode, the image actually renders. Any idea how to render an image? </p>
P粉236743689
P粉236743689

reply all(1)
P粉704066087

It should be defined as a computed property because it depends on the value of another property (do the same for name):

<script setup>

  import { useAuth0 } from '@auth0/auth0-vue';
  
  let auth0 = process.client ? useAuth0() : undefined;

  const name = computed(()=>auth0?.isAuthenticated ? auth0?.user?.value.nickname:'');
  const image = computed(()=>auth0?.isAuthenticated ? auth0?.user?.value.picture:'');


</script>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template