docs(Style): use composition api

This commit is contained in:
chenjiahan 2020-12-13 17:00:10 +08:00
parent 57c860afb8
commit 497f36a2d3
2 changed files with 42 additions and 34 deletions

View File

@ -62,7 +62,7 @@ const i18n = {
}; };
export default { export default {
data() { setup() {
const t = useTranslate(i18n); const t = useTranslate(i18n);
const show = ref(false); const show = ref(false);

View File

@ -21,9 +21,11 @@
</transition> </transition>
</template> </template>
<script> <script lang="ts">
export default { import { reactive, toRefs } from 'vue';
i18n: { import { useTranslate } from '@demo/use-translate';
const i18n = {
'zh-CN': { 'zh-CN': {
hairline: '1px 边框', hairline: '1px 边框',
ellipsis: '文字省略', ellipsis: '文字省略',
@ -43,24 +45,30 @@ export default {
text2: text2:
'This is a paragraph that displays up to two lines of text, and the rest of the text will be omitted.', 'This is a paragraph that displays up to two lines of text, and the rest of the text will be omitted.',
}, },
}, };
data() { export default {
return { setup() {
const t = useTranslate(i18n);
const state = reactive({
show: false, show: false,
transitionName: '', transitionName: '',
}; });
},
methods: { const animate = (transitionName: string) => {
animate(transitionName) { state.show = true;
this.show = true; state.transitionName = transitionName;
this.transitionName = transitionName;
setTimeout(() => { setTimeout(() => {
this.show = false; state.show = false;
}, 500); }, 500);
}, };
return {
...toRefs(state),
t,
animate,
};
}, },
}; };
</script> </script>