🐛 修复数据更新子组件不更新的bug

This commit is contained in:
BTMuli
2024-01-06 18:36:09 +08:00
parent 4614a453ef
commit cbda4b3d0b
3 changed files with 27 additions and 13 deletions

View File

@@ -100,9 +100,10 @@ interface TwcCharacterProps {
item: TGApp.App.Character.WikiBriefInfo; item: TGApp.App.Character.WikiBriefInfo;
} }
interface TwcCharacterEmits { type TwcCharacterEmits = {
error: (err: Error) => void; (e: "update:modelValue", value: TGApp.App.Character.WikiBriefInfo): void;
} (e: "error"): void;
};
const props = defineProps<TwcCharacterProps>(); const props = defineProps<TwcCharacterProps>();
const emits = defineEmits<TwcCharacterEmits>(); const emits = defineEmits<TwcCharacterEmits>();
@@ -126,7 +127,7 @@ const box = computed(() => {
async function loadData(): Promise<void> { async function loadData(): Promise<void> {
try { try {
const res = await getWikiData("Character", props.item.id); const res = await getWikiData("Character", props.item.id.toString());
if (res === undefined) return; if (res === undefined) return;
data.value = res.default; data.value = res.default;
showSnackbar({ showSnackbar({
@@ -139,7 +140,7 @@ async function loadData(): Promise<void> {
color: "error", color: "error",
}); });
console.error(error); console.error(error);
emits("error", error); emits("error");
} }
} }

View File

@@ -2,8 +2,8 @@
<div class="twc-constellations-box"> <div class="twc-constellations-box">
<v-tabs v-model="tab"> <v-tabs v-model="tab">
<v-tab <v-tab
v-for="item in props.data" v-for="(item, index) in props.data"
:key="item.Id" :key="index"
:value="item.Name" :value="item.Name"
:title="item.Name" :title="item.Name"
class="twc-constellation-tab" class="twc-constellation-tab"
@@ -16,8 +16,8 @@
<v-window v-model="tab"> <v-window v-model="tab">
<v-window-item <v-window-item
:value="item.Name" :value="item.Name"
v-for="item in props.data" v-for="(item, index) in props.data"
:key="item.Id" :key="index"
class="twc-constellation-desc" class="twc-constellation-desc"
> >
<span v-html="parseHtmlText(item.Description)"></span> <span v-html="parseHtmlText(item.Description)"></span>
@@ -26,7 +26,7 @@
</div> </div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref } from "vue"; import { onBeforeMount, onMounted, ref, watch } from "vue";
import { parseHtmlText } from "../../utils/toolFunc"; import { parseHtmlText } from "../../utils/toolFunc";
@@ -36,6 +36,14 @@ interface TwcConstellationProps {
const props = defineProps<TwcConstellationProps>(); const props = defineProps<TwcConstellationProps>();
const tab = ref<string>(); const tab = ref<string>();
function loadData(): void {
tab.value = props.data[0].Name;
}
onMounted(loadData);
watch(() => props.data, loadData);
</script> </script>
<style lang="css" scoped> <style lang="css" scoped>
.twc-constellations-box { .twc-constellations-box {

View File

@@ -23,7 +23,7 @@
</div> </div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { onMounted, ref } from "vue"; import { onMounted, ref, watch } from "vue";
import { parseHtmlText } from "../../utils/toolFunc"; import { parseHtmlText } from "../../utils/toolFunc";
@@ -35,10 +35,15 @@ const props = defineProps<TwcSkillsProps>();
const tab = ref<string>(); const tab = ref<string>();
const tabValues = ref<Array<{ name: string; icon: string }>>([]); const tabValues = ref<Array<{ name: string; icon: string }>>([]);
onMounted(() => { function loadData(): void {
tabValues.value = [];
props.data.map((i) => tabValues.value.push({ name: i.Name, icon: i.Icon })); props.data.map((i) => tabValues.value.push({ name: i.Name, icon: i.Icon }));
tab.value = tabValues.value[0].name; tab.value = tabValues.value[0].name;
}); }
onMounted(loadData);
watch(() => props.data, loadData);
</script> </script>
<style lang="css" scoped> <style lang="css" scoped>
.twc-skills-box { .twc-skills-box {