Skip to content

Instantly share code, notes, and snippets.

@saninmersion
Created July 24, 2019 07:48
Show Gist options
  • Save saninmersion/49778b38cb8af44ff5dc288a1791791b to your computer and use it in GitHub Desktop.
Save saninmersion/49778b38cb8af44ff5dc288a1791791b to your computer and use it in GitHub Desktop.
Slug Component Example
<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