Created
July 24, 2019 07:48
-
-
Save saninmersion/49778b38cb8af44ff5dc288a1791791b to your computer and use it in GitHub Desktop.
Slug Component Example
This file contains hidden or 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
<template> | |
<input type="text" v-model="value"> | |
</template> | |
<script type="text/ecmascript-6"> | |
export default { | |
name: "slug", | |
props: { | |
title:{ default:"" } | |
apiUrl: { required: true }, | |
}, | |
data() { | |
return { | |
value: "", | |
autoGenerate: true, | |
} | |
}, | |
watch: { | |
title: { | |
handler: function(title) { | |
this.generate(title) | |
}, | |
}, | |
}, | |
methods: { | |
generate(title) { | |
const vm = this | |
this.$root.disableInterceptor() | |
window.axios.get(vm.apiUrl, { | |
params: { | |
title: title, | |
}, | |
}).then(function(response) { | |
vm.value = response.data | |
vm.$emit("change", { "slug": response.data }) | |
vm.$root.enableInterceptor() | |
}).catch(function(error) { | |
console.error(error) | |
vm.$root.enableInterceptor() | |
}) | |
}, | |
}, | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment