Vue3+TypeScript踩坑

1. type assertion expressions can only be used in TypeScript files.Vetur(8016)

解决方案:在<script>标签上加lang="ts"

<script lang="ts">
</script>

2.类型“string | null”的参数不能赋给类型“string”的参数。不能将类型“null”分配给类型“string”。

 JSON.parse(localStorage.getItem('list'))

JSON.parse方法是json字符串转换为json对象,使用localStorage.getItem获取的值是null

解决方案:在<script>标签上加lang="ts"

 JSON.parse(localStorage.getItem('list')  || '[]')

猜你喜欢

转载自blog.csdn.net/qq_38367703/article/details/126984867