custom.d.ts
在src目录下新建custom.d.ts(只要以.d.ts结尾即可),在其中存放全局类型。此时整个src目录都可以在不引用的前提下使用该类型。
type RecordItem = {
tags: string[]
notes: string
type: string
amount: number // 数据类型 object | string
createdAt?: Date // 类 / 构造函数
}
labels.vue
<template>
<Layout>
<div class="tags">
<router-link class="tag"
v-for="tag in tags" :key="tag.id"
:to="`/labels/edit/${tag.id}`">
<span>{{ tag.name }}</span>
<Icon name="edit"/>
</router-link>
</div>
<div class="createTag-wrapper">
<Button class="createTag"
@click="createTag">
新建标签
</Button>
</div>
</Layout>
</template>
<script lang="ts">
import Vue from 'vue';
import {Component} from 'vue-property-decorator';
import tagListModel from '@/models/tagListModel';
import Button from '@/components/Button.vue';
tagListModel.fetch();
@Component({
components: {Button}
})
export default class Labels extends Vue {
tags = tagListModel.data;
createTag() {
const name = window.prompt('请输入标签名');
if (name) {
const message = tagListModel.create(name);
if (message === 'duplicated') {
window.alert('标签名重复了');
} else if (message === 'success') {
window.alert('添加成功');
}
}
}
}
</script>
<style lang="scss" scoped>
.tags {
background: white;
font-size: 16px;
padding-left: 16px;
> .tag {
min-height: 44px;
display: flex;
align-items: center;
justify-content: space-between;
border-bottom: 1px solid #e6e6e6;
svg {
width: 18px;
height: 18px;
margin-right: 16px;
}
}
}
.createTag {
background: #ffb13d;
color: black;
border-radius: 4px;
border: none;
height: 40px;
padding: 0 16px;
&-wrapper { //父元素
text-align: center;
padding: 16px;
margin-top: 44-16px;
}
}
</style>