fix: to composition api

This commit is contained in:
Mohamed Maoulainine Maoulainine
2025-02-26 03:39:59 +01:00
parent 0733f8d5af
commit f48b570494
4 changed files with 40 additions and 61 deletions

View File

@ -9,46 +9,36 @@
</div>
</template>
<script>
import { ref, onMounted } from "vue";
<script setup lang="ts">
import { ref, defineProps, onMounted } from "vue";
import axios from "axios";
export default {
props: {
title: String,
description: String,
},
const props = defineProps<{
title: string;
description: string;
}>();
setup(props) {
const expanded = ref(false);
const currentDescription = ref(props.description);
const expanded = ref(false);
const currentDescription = ref(props.description);
const fetchData = async () => {
try {
const response = await axios.get("http://localhost:5000/data"); // to edit later!
currentDescription.value = response.data[0].canva_data;
} catch (error) {
console.error("Erreur lors de la récupération des données :", error);
}
};
const toggleExpand = async () => {
if (!expanded.value) {
await fetchData();
} else {
currentDescription.value = props.description;
}
expanded.value = !expanded.value;
};
return {
expanded,
currentDescription,
toggleExpand
};
const fetchData = async () => {
try {
const response = await axios.get("http://localhost:5000/data"); // Update the URL if needed
currentDescription.value = response.data[0].canva_data;
} catch (error) {
console.error("Erreur lors de la récupération des données :", error);
}
};
const toggleExpand = async () => {
if (!expanded.value) {
await fetchData();
} else {
currentDescription.value = props.description;
}
expanded.value = !expanded.value;
};
</script>