Pass props based on tests within computed properties
<p>I ran into a problem with a simple test in Nuxt 3's <code>computed()</code> property. </p>
<pre class="brush:php;toolbar:false;">const test = computed(() => {
if (process.client) {
console.log('Worked. Is it a mobile device?', window.innerWidth < 768)
return window.innerWidth < 768
} else {
console.log('Didn't work')
return
}
})</pre>
<p>The result of the computed property is always correct, but I want to use it in the template below to pass props conditionally. </p>
<pre class="brush:php;toolbar:false;"><Loader
v-if="isLoading"
:images="test ? brands.desktopLoaderImages : brands.mobileLoaderImages"
/></pre>
<p>The problem is that regardless of the result, brands.mobileLoaderImages is always passed as props to my component and I can't figure out why. </p>
<p>I tried using a different technique to determine the screen size other than <code>window.innerWidth</code>, like a dedicated module like <code>@vueuse/core</code> but the result it's the same. I'm guessing the problem might be from Vue's lifecycle or something? </p>