mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-07 05:31:05 +08:00
54 lines
1.2 KiB
Plaintext
54 lines
1.2 KiB
Plaintext
```html
|
|
<!-- YourPage.vue -->
|
|
|
|
<template>
|
|
<div v-if="!loading && data && data.subdocuments.length">
|
|
<PageLayout :user="data.user">
|
|
<DocumentHeader :document="data.document" />
|
|
<DocumentList :documents="data.subdocuments" />
|
|
</PageLayout>
|
|
</div>
|
|
<p v-if="loading">
|
|
Loading...
|
|
</p>
|
|
<p v-if="error">
|
|
There was an error fetching the data!
|
|
</p>
|
|
</template>
|
|
<script>
|
|
import { ref } from 'vue';
|
|
|
|
import PageLayout from './PageLayout';
|
|
import DocumentHeader from './DocumentHeader';
|
|
import DocumentList from './DocumentList';
|
|
|
|
export default {
|
|
name: 'DocumentScreen',
|
|
setup() {
|
|
const data = ref(null);
|
|
const loading = ref(true);
|
|
const error = ref(null);
|
|
fetch('https://your-restful-endpoint')
|
|
.then((res) => {
|
|
if (!res.ok) {
|
|
error.value = res.statusText;
|
|
}
|
|
return res;
|
|
})
|
|
.then((res) => res.json())
|
|
.then((requestData) => {
|
|
data.value = requestData;
|
|
loading.value = false;
|
|
})
|
|
.catch(() => {
|
|
error.value = 'error';
|
|
});
|
|
return {
|
|
error,
|
|
loading,
|
|
data,
|
|
};
|
|
},
|
|
};
|
|
</script>
|
|
``` |