You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Pinia Store更新值后失去响应性问题求助

Pinia数组替换后UI不更新问题

我在沙箱中运行示例可正常工作,说明问题出在我的项目配置里。涉及的项目文件:

  • stores/cardStore.js - Store定义文件
  • composables/loadData.js - 首次更新Store数组的文件
  • composables/discardSavedCard.js - 更新数组但不触发UI更新的文件
  • components/imageLayers/ImageLayers.js - 未更新的UI组件

我的Pinia Store是一个包含对象数组的对象。修改数组内对象的属性时,使用该属性的UI部分可正常更新;但将嵌套数组替换为包含新对象的新数组时,状态已改变但UI未更新,仿佛数组未发生变化。

更新Store脚本

import { useExampleStore } from "@/stores/exampleStore";

const updateStore = () => {
    const exampleStore = useExampleStore();

    exampleStore.array = [{prop:'newprop'}];
};

示例UI

<template>
    <div> {{exampleStore.array[0].prop}} </div>
</template>

<script setup>
import { useExampleStore } from "@/stores/exampleStore";
const exampleStore = useExampleStore();
</script>

@/stores/exampleStore.js

import { defineStore } from "pinia";

export const useExampleStore = defineStore("exampleStore", {
  state: () => ({}),
});

内容的提问来源于stack exchange,提问作者franka

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 13:32:13