Skip to content

Commit

Permalink
refactor: refactor for <script setup>
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Dec 23, 2020
1 parent eefbd76 commit 5ba4ea2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 50 deletions.
23 changes: 7 additions & 16 deletions src/client/app/components/Debug.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,15 @@
</div>
</template>

<script lang="ts">
import { defineComponent, ref, watch } from 'vue'
<script setup lang="ts">
import { ref, watch } from 'vue'
export default defineComponent({
setup() {
const el = ref<HTMLElement | null>(null)
const open = ref(false)
const el = ref<HTMLElement | null>(null)
const open = ref(false)
watch(open, (value) => {
if (value === false) {
el.value!.scrollTop = 0
}
})
return {
el,
open
}
watch(open, (value) => {
if (value === false) {
el.value!.scrollTop = 0
}
})
</script>
Expand Down
40 changes: 15 additions & 25 deletions src/client/theme-default/components/LastUpdated.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,29 @@
</p>
</template>

<script lang="ts">
import { defineComponent, ref, computed, onMounted } from 'vue'
<script setup lang="ts">
import { ref, computed, onMounted } from 'vue'
import { useSiteDataByRoute, usePageData } from 'vitepress'
export default defineComponent({
setup() {
const site = useSiteDataByRoute()
const page = usePageData()
const site = useSiteDataByRoute()
const page = usePageData()
const datetime = ref('')
const datetime = ref('')
const hasLastUpdated = computed(() => {
const lu = site.value.themeConfig.lastUpdated
const hasLastUpdated = computed(() => {
const lu = site.value.themeConfig.lastUpdated
return lu !== undefined && lu !== false
})
const prefix = computed(() => {
const p = site.value.themeConfig.lastUpdated
return lu !== undefined && lu !== false
})
return p === true ? 'Last Updated' : p
})
const prefix = computed(() => {
const p = site.value.themeConfig.lastUpdated
onMounted(() => {
datetime.value = new Date(page.value.lastUpdated).toLocaleString('en-US')
})
return p === true ? 'Last Updated' : p
})
return {
hasLastUpdated,
prefix,
datetime
}
}
onMounted(() => {
datetime.value = new Date(page.value.lastUpdated).toLocaleString('en-US')
})
</script>

Expand Down
10 changes: 1 addition & 9 deletions src/client/theme-default/components/PageFooter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,9 @@
</footer>
</template>

<script lang="ts">
import { defineComponent } from 'vue'
<script setup lang="ts">
import EditLink from './EditLink.vue'
import LastUpdated from './LastUpdated.vue'
export default defineComponent({
components: {
EditLink,
LastUpdated
}
})
</script>

<style scoped>
Expand Down

1 comment on commit 5ba4ea2

@vercel
Copy link

@vercel vercel bot commented on 5ba4ea2 Dec 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.