Skip to content

Instantly share code, notes, and snippets.

@mariobuikhuizen
Last active December 3, 2020 13:15
Show Gist options
  • Save mariobuikhuizen/1c48a354600e4f4212bf003504a2c091 to your computer and use it in GitHub Desktop.
Save mariobuikhuizen/1c48a354600e4f4212bf003504a2c091 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"import ipyvuetify as vy\n",
"import traitlets\n",
"\n",
"class MyLocalstorage(vy.VuetifyTemplate):\n",
" template = traitlets.Unicode('''\n",
" <template>\n",
" <div>\n",
" <v-text-field v-model=\"my_value\" label=\"Enter value\" />\n",
" </div>\n",
" </template>\n",
" <script>\n",
" modules.export = {\n",
" created() {\n",
" this.my_value = localStorage.getItem('myKey');\n",
" addEventListener('storage', (event) => {\n",
" if (event.key === 'myKey') {\n",
" this.my_value = localStorage.getItem('myKey');\n",
" }\n",
" });\n",
" },\n",
" watch: {\n",
" my_value(value) {\n",
" localStorage.setItem('myKey', value);\n",
" }\n",
" }\n",
" }\n",
" </script>\n",
" ''').tag(sync=True)\n",
" \n",
" my_value = traitlets.Unicode().tag(sync=True)\n",
" \n",
"my_storage = MyLocalstorage()\n",
"my_storage"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"my_storage.my_value = 'from python'"
]
},
{
"cell_type": "raw",
"metadata": {},
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.0"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment