diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-07 18:09:19 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-07 18:09:19 +0000 |
commit | 3290d46655f07d7ae3dca788d6df9f326972ffd8 (patch) | |
tree | 0d24713e1592cdd3583257f14a52d46a22539ed1 /app/assets/javascripts/vue_shared | |
parent | c6b3ec3f56fa32a0e0ed3de0d0878d25f1adaddf (diff) | |
download | gitlab-ce-3290d46655f07d7ae3dca788d6df9f326972ffd8.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/vue_shared')
-rw-r--r-- | app/assets/javascripts/vue_shared/components/local_storage_sync.vue | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/app/assets/javascripts/vue_shared/components/local_storage_sync.vue b/app/assets/javascripts/vue_shared/components/local_storage_sync.vue new file mode 100644 index 00000000000..b5d6b872547 --- /dev/null +++ b/app/assets/javascripts/vue_shared/components/local_storage_sync.vue @@ -0,0 +1,39 @@ +<script> +export default { + props: { + storageKey: { + type: String, + required: true, + }, + value: { + type: String, + required: false, + default: '', + }, + }, + watch: { + value(newVal) { + this.saveValue(newVal); + }, + }, + mounted() { + // On mount, trigger update if we actually have a localStorageValue + const value = this.getValue(); + + if (value && this.value !== value) { + this.$emit('input', value); + } + }, + methods: { + getValue() { + return localStorage.getItem(this.storageKey); + }, + saveValue(val) { + localStorage.setItem(this.storageKey, val); + }, + }, + render() { + return this.$slots.default; + }, +}; +</script> |