I’m using vuejs 3 (cdn) fetch a list o files.
My code is working with button click, but would like to modify to fetch files at initial page load.
<script>
const {
createApp,
ref
} = Vue
createApp({
setup() {
const files = ref([]);
function getfiles() {
const res1 = fetch('/api/files.json')
.then(response => response.json())
.then(data => {
this.requestfiles = data.data.files;
})
.catch(error => {
console.error("There was an error! ", error)
});
}
return {
getfiles,
files
}
}
}).mount('#app');
</script>