1. 再次封装 recordListModel
- 声明一个 type
type RecordListModel = {
data:
}
- 强制断言
data: [] as RecordItem[]
2. 给 window 加上属性
interface Window {
tagList: Tag[]
}
3. 用 window 来封装 api
window.updateTag = (id: string, object: Exclude<Tag, 'id'>){
}
interface Window {
tagList: Tag[],
createTag: (name: string) => void,
removeTag: (id:string) => boolean,
updateTag: TagListModel['update']
}
4. 目前代码存在的问题
- 全局变量太多\
- 严重依赖 window
5. 目前代码存在的 bug
- 导致原因,数据引用和对象引用,解决办法数据和对象都放 computed,computed 的功能是原来的值变化就会更新外面的值
6. 使用 store 小技巧
import store2 from '@/store/index2.ts'
Vue.prototype.$store2 = store2