■ 渲染state中定义image
template
1 | <img class="user-avatar rounded-circle mr-2" :src="avatar" alt="User Avatar" /> |
script
1 | const defaultAvatar = require('@/assets/images/avatars/0.jpg'); |
import的方式可能会有错误提示,
require
的方式相当于import * as defaultAvatar
■ 循环渲染state中定义数组
和组件内的静态属性不同,state中属性循环需要制定
:key
,保证列表项目的唯一性,做渲染优化
1 | <d-dropdown-item v-for="item in notifications.list" v-bind:key="item"> |
■ Parameter ‘to’ implicitly has an ‘any’ type.
typescript进行结构时需要声明结构对象类型,为了便捷,通常使用
any
对于类型强迫症可以找到精准定义来声明
1 | const actions = { |
■ vue router Navigating to current location (“/login”) is not allowed
这个错误表示当前已经在这个路由,所以无法再进行push
1 | @Component({ |
■ Property ‘history’ does not exist on type ‘VueRouter’.
- by adding // @ts-ignore to the line above
- else…
1 | const router: any = this.$router; |
■ Cannot find module ‘’ with typescript
1 | > 11 | import Loading from '~components/common/loading'; |
解决方案
1 | import Loading from '~components/common/loading.vue'; |
- 参考链接