Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

通过直接导入json文件的方式可以预览,但是使用fetch获取就无法预览 #343

Open
kkokoo opened this issue Sep 7, 2024 · 1 comment

Comments

@kkokoo
Copy link

kkokoo commented Sep 7, 2024

<script setup> // import photosData from '../../public/photos.json' import { ref, onMounted } from 'vue'; const photosData = ref([]); async function fetchData() { try { const response = await fetch('../../public/photos.json') const data = await response.json() photosData.value = data } catch (error) { console.error('Error fetching data:', error) } } onMounted(async () => { await fetchData(); }); </script>
照片墙

{{ photo.title }}

@kkokoo
Copy link
Author

kkokoo commented Sep 7, 2024

解决了,删除<viewer></viewer>,改为<div v-viewer><div>

<div v-viewer class="item">
         <span v-for="photo in photosData" :key="photo.title">
                    <img :src="photo.src" :alt="photo.title">
               <p>{{ photo.title }}</p>
        </span>
</div>
<viewer class="item">
         <span v-for="photo in photosData" :key="photo.title">
                    <img :src="photo.src" :alt="photo.title">
               <p>{{ photo.title }}</p>
        </span>
   </viewer>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant