VueCli3构建TS项目的方法步骤

2020-06-14 06:18:51易采站长站整理
cookie
,
global cache

action(异步)
: api的操作, 调用方式:
this.$store.dispatch(functionName, data)

mutations(同步)
: dom相关操作,方法名一般使用常量,
调用方式:
this.$store.commit(mutationsName, data)


this.$store.getters[XXX] => this.$store.getters[namespaced/XXX]this.$store.dispatch(XXX, {}) => this.$store.dispatch(namespaced/XXX, {})
this.$store.commit(XXX, {}) => this.$store.commit(namespaced/XXX, {})

组件内的Vue


<template>
<div>
<div>用户名:<input type="text" v-model="username" /></div>
<div>密码:<input type="password" v-model="passwd" /></div>

<div>{{computedMsg}}</div>
</div>
</template>

<script lang="ts">
import { Component, Prop, Vue, Provide } from 'vue-property-decorator'

// 引入组件
@Component({
components: {
// input
}
})
export default class Login extends Vue {
// data
@Provide() private username: string = ''
@Provide() private passwd: string = ''

// methods
login (u: string, p: string) {
}

// computed
get computedMsg () {
return 'username: ' + this.username
}

// life cycle
mounted () {
}
}
</script>

other

公用组件:

dateRange
,
pagination
,
icon-font
,
clock
,
proxyAutocomplete
,
dialog

全局注入


Vue.component(modal.name, modal) // dialog
Vue.component(pagination.name, pagination) // 分页
Vue.component(dateRange.name, dateRange) // 日期
Vue.component(proxyAutocomplete.name, proxyAutocomplete) // 远程模糊搜索
Vue.component(card.name, card) // el-tabs
Vue.component(tabLoad.name, tabLoad) // el-tabs

main.ts
中引入公用组件文件夹下的
useElement


import '@/components/useElement'

一些问题

不能直接new


// 'new' expression, whose target lacks a construct signature, implicitly has an 'any' type.