这是在 vue3 (pinia) aonf 中使用 vue 3 中的组合 api 进行状态管理时出现的问题,在获得来自 countryCodes 的成功查询结果(数组)后,我想将 countryCodes 数组的所有项目复制到中定义的国家数组中状态,但是在使用 forEach 方法以及其他几种克隆数组的方法时,我遇到了错误“属性 'forEach' 在类型 'Readonly<Ref<Readonly>>' 上不存在”“注意:我正在使用类型脚本,如何解决这个问题?
export const getAllCityAndCountries = defineStore("main", {
state: () => {
return {
countries: [
{
code: '880',
name: 'Bangladesh',
emoji: ''
}
]
}
},
actions: {
getCountries() {
const { result, error } = useQuery(gql`${getCountryCodes}`,
{
limit: 250,
skip: 0
}
)
let countryCodes = useResult(result, null, data => data.getCountryCodes.result.countryCodes)
countryCodes.forEach(val => this.countries.push(Object.assign({}, val)));
},
}
})