Fetch and display HTML
Sometimes you just want to fetch some HTML from the server, display them right in your application, and call it done.
Sometimes you just want to fetch some HTML from the server, display them right in your application, and call it done.
Detect if the user has scrolled to bottom of a container element and executed a function (for example, load more posts Ă la infinite scrolling).
A simple directive that triggers a function if the user clicks outside of the bound element.
<template>
<div v-clickaway="hideMe">Hide me</div>
</template>
<script>
Vue.directive('clickaway', {
bind (el, { value }) {
if (typeof value !== 'function') {
console.warn(`Expect a function, got ${value}`)
return
}
document.addEventListener('click', e => el.contains(e.target) || value())
}
})
export default {
methods: {
hideMe () {
// your logic here
}
}
}
</script>
Prevent your methods or events from being executed so often using lodash’s debounce()
function.
Automatically set focus into an input element when it’s inserted into the document.