Skip to content

Instantly share code, notes, and snippets.

@se1983
Created June 18, 2021 07:40
Show Gist options
  • Save se1983/9d98ba1e42d5a750b1ef531b8a1b8d24 to your computer and use it in GitHub Desktop.
Save se1983/9d98ba1e42d5a750b1ef531b8a1b8d24 to your computer and use it in GitHub Desktop.
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