docs(Icon): use composition api

This commit is contained in:
chenjiahan 2020-12-13 13:53:51 +08:00
parent f66dcdc8c0
commit 5582f8a583

View File

@ -95,7 +95,10 @@
<script> <script>
import icons from '@vant/icons'; import icons from '@vant/icons';
import { ref } from 'vue';
import { useTranslate } from '@demo/use-translate';
import { RED } from '../../utils/constant'; import { RED } from '../../utils/constant';
import Notify from '../../notify';
// from https://30secondsofcode.org // from https://30secondsofcode.org
function copyToClipboard(str) { function copyToClipboard(str) {
@ -121,8 +124,7 @@ function copyToClipboard(str) {
} }
} }
export default { const i18n = {
i18n: {
'zh-CN': { 'zh-CN': {
title: '图标列表', title: '图标列表',
badge: '徽标提示', badge: '徽标提示',
@ -145,20 +147,14 @@ export default {
color: 'Icon Color', color: 'Icon Color',
size: 'Icon Size', size: 'Icon Size',
}, },
},
data() {
this.RED = RED;
this.icons = icons;
return {
tab: 0,
demoIcon: 'chat-o',
demoImage: 'https://b.yzcdn.cn/vant/icon-demo-1126.png',
}; };
},
methods: { export default {
copy(icon, option = {}) { setup() {
const t = useTranslate(i18n);
const tab = ref(0);
const copy = (icon, option = {}) => {
let tag = `<van-icon name="${icon}"`; let tag = `<van-icon name="${icon}"`;
if ('dot' in option) { if ('dot' in option) {
tag = `${tag} ${option.dot ? 'dot' : ''}`; tag = `${tag} ${option.dot ? 'dot' : ''}`;
@ -175,13 +171,23 @@ export default {
tag = `${tag} />`; tag = `${tag} />`;
copyToClipboard(tag); copyToClipboard(tag);
this.$notify({ Notify({
type: 'success', type: 'success',
duration: 1500, duration: 1500,
className: 'demo-icon-notify', className: 'demo-icon-notify',
message: `${this.t('copied')}${tag}`, message: `${t('copied')}${tag}`,
}); });
}, };
return {
t,
tab,
RED,
copy,
icons,
demoIcon: 'chat-o',
demoImage: 'https://b.yzcdn.cn/vant/icon-demo-1126.png',
};
}, },
}; };
</script> </script>