Added an example button that is included as another component to show how to add additional .vue includes into other Vue files

This commit is contained in:
lwcrosier 2025-12-03 22:03:36 -05:00
parent 852a89ee71
commit 769b44c494
2 changed files with 37 additions and 9 deletions

5
src/views/ButtonTest.vue Normal file
View File

@ -0,0 +1,5 @@
<template>
<button class="btn btn-primary">"Test Button"</button>
</template>

View File

@ -1,20 +1,25 @@
<template> <template>
<div class="container"> <div class="container">
<button class="btn btn-primary" @click="fetchCaddyConfig">Get Config</button>
<br/>
<p> {{ myData }}</p> <br />
<p>{{ caddyConfig }}</p>
<ButtonTest />
</div> </div>
</template> </template>
<script> <script>
import ButtonTest from '../views/ButtonTest.vue';
export default { export default {
components: {
ButtonTest
},
data() { data() {
return { return {
myData: null, caddyConfig: null,
isLoading: false, isLoading: false,
error: null error: null
}; };
@ -26,14 +31,29 @@
let fetch_data = null; let fetch_data = null;
try {
const response = await fetch('http://localhost:2019/config/', {
mode: 'cors',
method: 'GET'
});
if(!response.ok) {
throw new Error('Error in fetch request');
}
fetch_data = await response.json();
this.caddyConfig = fetch_data;
} catch (error) {
this.error = "Could not fetch Caddy Config: " + error.message;
console.error(error);
}
/*
fetch('http://localhost:2019/config/', { fetch('http://localhost:2019/config/', {
mode: 'cors', mode: 'cors',
method: 'GET' method: 'GET'
}) })
//.then(response => console.log(response))
.then(response => response.json()) .then(response => response.json())
//then(responseJson => fetch_data = responseJson)
//.then(data => console.log(data))
.then(data => { .then(data => {
fetch_data = data; fetch_data = data;
this.myData = data; this.myData = data;
@ -43,8 +63,11 @@
this.error = error; this.error = error;
} }
); );
*/
} }
},
mounted() {
this.fetchCaddyConfig();
} }
} }