Skip to content

Commit

Permalink
feat: add demo
Browse files Browse the repository at this point in the history
  • Loading branch information
jahnli committed Oct 1, 2024
1 parent 5975922 commit ae31b9c
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/image/demos/enUS/custom-error.demo.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<markdown>
# The custom loading failed. Procedure

In most cases, can use 'fallback-src' to set the image when it fails.
</markdown>

<script lang="ts">
import { defineComponent, ref } from 'vue'
import { ImageOutline as ImageOutlineIcon } from '@vicons/ionicons5'
export default defineComponent({
components: {
ImageOutlineIcon
},
setup() {
const url = ref('blablabla')
const refresh = () => {
url.value = 'https://07akioni.oss-cn-beijing.aliyuncs.com/07akioni.jpeg'
}
const reloadError = () => {
url.value = 'blablabla'
}
return {
url,
refresh,
reloadError
}
}
})
</script>

<template>
<n-flex vertical inline>
<n-flex>
<n-button type="error" @click="reloadError">
Load Fail
</n-button>
<n-button type="primary" @click="refresh">
Refresh
</n-button>
</n-flex>
<n-image width="100" :src="url">
<template #error>
<n-icon :size="100" color="lightGrey">
<ImageOutlineIcon />
</n-icon>
</template>
</n-image>
</n-flex>
</template>
50 changes: 50 additions & 0 deletions src/image/demos/zhCN/custom-error.demo.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<markdown>
# 自定义加载失败

多数情况下可以使用 `fallback-src` 设定失败时的图像。
</markdown>

<script lang="ts">
import { defineComponent, ref } from 'vue'
import { ImageOutline as ImageOutlineIcon } from '@vicons/ionicons5'
export default defineComponent({
components: {
ImageOutlineIcon
},
setup() {
const url = ref('人生嘛,失败总是难免的')
const refresh = () => {
url.value = 'https://07akioni.oss-cn-beijing.aliyuncs.com/07akioni.jpeg'
}
const reloadError = () => {
url.value = '人生嘛,失败总是难免的'
}
return {
url,
refresh,
reloadError
}
}
})
</script>

<template>
<n-flex vertical inline>
<n-flex>
<n-button type="error" @click="reloadError">
加载失败
</n-button>
<n-button type="primary" @click="refresh">
刷新
</n-button>
</n-flex>
<n-image width="100" :src="url">
<template #error>
<n-icon :size="100" color="lightGrey">
<ImageOutlineIcon />
</n-icon>
</template>
</n-image>
</n-flex>
</template>

0 comments on commit ae31b9c

Please sign in to comment.