Created
June 18, 2021 07:40
-
-
Save se1983/9d98ba1e42d5a750b1ef531b8a1b8d24 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const app = Vue.createApp({ | |
data: function () { | |
return { | |
output: null | |
} | |
} | |
}) | |
app.component('poll-button', { | |
data: function () { | |
return { | |
isLoading: true, | |
isError: false, | |
} | |
}, | |
created() { | |
this.pollStatus() | |
}, | |
methods: { | |
pollStatus() { | |
this.attrs = setInterval(() => { | |
axios.get( | |
this.$root.$refs.input_url.value, | |
{validateStatus: false} | |
).then(response => { | |
this.isLoading = response.status != 200; | |
this.isError = response.status >= 400 | |
}).catch(function (error) { | |
this.isError = true | |
}) | |
}, 3000) | |
}, | |
submit() { | |
console.log(this.$root.$refs.input_url.value) | |
axios.get(this.$root.$refs.input_url.value) | |
.then(response => (this.$root.output = response.data)) | |
}, | |
}, | |
template: `<button | |
class="button is-large is-fullwidth is-rounded is-outlined" | |
v-on:click="submit" | |
v-bind:class="{ | |
'is-loading': isLoading, | |
'is-success': !isError && !isLoading, | |
'is-danger': isError, | |
}" | |
>Submit</button>` | |
}); | |
app.mount('#app') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment