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 {
data() {
setup() {
const t = useTranslate(i18n);
const show = ref(false);

View File

@ -21,46 +21,54 @@
</transition>
</template>
<script>
export default {
i18n: {
'zh-CN': {
hairline: '1px 边框',
ellipsis: '文字省略',
animation: '动画',
toggle: '切换动画',
text1: '这是一段最多显示一行的文字,后面的内容会省略',
text2:
'这是一段最多显示两行的文字,后面的内容会省略。这是一段最多显示两行的文字,后面的内容会省略',
},
'en-US': {
hairline: 'Hairline',
ellipsis: 'Text Ellipsis',
animation: 'Animation',
toggle: 'Switch animation',
text1:
'This is a paragraph that displays up to one line of text, and the rest of the text will be omitted.',
text2:
'This is a paragraph that displays up to two lines of text, and the rest of the text will be omitted.',
},
},
<script lang="ts">
import { reactive, toRefs } from 'vue';
import { useTranslate } from '@demo/use-translate';
data() {
return {
const i18n = {
'zh-CN': {
hairline: '1px 边框',
ellipsis: '文字省略',
animation: '动画',
toggle: '切换动画',
text1: '这是一段最多显示一行的文字,后面的内容会省略',
text2:
'这是一段最多显示两行的文字,后面的内容会省略。这是一段最多显示两行的文字,后面的内容会省略',
},
'en-US': {
hairline: 'Hairline',
ellipsis: 'Text Ellipsis',
animation: 'Animation',
toggle: 'Switch animation',
text1:
'This is a paragraph that displays up to one line of text, and the rest of the text will be omitted.',
text2:
'This is a paragraph that displays up to two lines of text, and the rest of the text will be omitted.',
},
};
export default {
setup() {
const t = useTranslate(i18n);
const state = reactive({
show: false,
transitionName: '',
};
},
});
methods: {
animate(transitionName) {
this.show = true;
this.transitionName = transitionName;
const animate = (transitionName: string) => {
state.show = true;
state.transitionName = transitionName;
setTimeout(() => {
this.show = false;
state.show = false;
}, 500);
},
};
return {
...toRefs(state),
t,
animate,
};
},
};
</script>