Hi there,
I'going to build a clickable icon/picture in dashboard 2. It should have 2 pictures, toggled by the click. f.ex. bulb-on.png and bulb-off.png.
How can I set the src of the img tag with a variable of my ui-template - node?
I tried setting an id to the img tag, getting the document id and setting the id.src - without success.
Here is an example code:
[
{
"id": "ad232f5935af2994",
"type": "ui-template",
"z": "f4e5a1a4a9bb3cc8",
"group": "91121ba376b2577b",
"page": "",
"ui": "",
"name": "Mein Button",
"order": 4,
"width": 0,
"height": 0,
"head": "",
"format": "<template>\n <div class=\"button\" id=\"divImage\" @click=\"toggleImage()\">\n <img src=\"\" alt=\"Klickbare Grafik\" id=\"buttonImage\"/>\n <p id=\"buttonText\">fridge</ p>\n </div>\n</template>\n\n<script>\n export default {\n data() {\n // define variables available component-wide\n // (in <template> and component functions)\n return {\n images: {\n image1: '/fridge_green.png', // Ersetzen Sie dies mit der URL Ihres ersten Bildes\n image2: '/fridge_red.png' // Ersetzen Sie dies mit der URL Ihres zweiten Bildes\n };\n image = document.getElementById(\"buttonImage\");\n image.src='/fridge.png';\n }\n },\n \n watch: {\n // watch for any changes of \"msg\"\n msg: function () {\n if (this.msg.payload && (this.msg.payload === this.images.image1 || this.msg.payload === this.images.image2)) {\n this.currentImage = this.msg.payload;\n }\n }\n },\n computed: {\n // automatically compute this variable\n // whenever VueJS deems appropriate\n },\n methods: {\n // expose a method to our <template> and Vue Application\n toggleImage: function () {\n this.currentImage = (this.currentImage === this.images.image1) ? this.images.image2 : this.images.image1;\n this.send({ payload: this.currentImage });\n }\n },\n\n mounted() {\n // code here when the component is first loaded\n this.currentImage = this.images.image1;\n },\n unmounted() {\n // code here when the component is removed from the Dashboard\n // i.e. when the user navigates away from the page\n }\n }\n\n</script>\n\n<style>\n .button {\n width: 128px;\n height: 128px;\n\n }\n</style>",
"storeOutMessages": true,
"passthru": true,
"resendOnRefresh": true,
"templateScope": "local",
"className": "",
"x": 430,
"y": 580,
"wires": [
[
"877e92118f317e5a"
]
]
},
{
"id": "91121ba376b2577b",
"type": "ui-group",
"name": "Seuchlicht",
"page": "c6ed8176203ca17b",
"width": 6,
"height": 1,
"order": 1,
"showTitle": true,
"className": "",
"visible": "true",
"disabled": "false",
"groupType": "default"
},
{
"id": "c6ed8176203ca17b",
"type": "ui-page",
"name": "Logger",
"ui": "6ffb10ff06c355be",
"path": "/page2",
"icon": "home",
"layout": "grid",
"theme": "6c7fce75833af206",
"breakpoints": [
{
"name": "Default",
"px": "0",
"cols": "3"
},
{
"name": "Tablet",
"px": "576",
"cols": "6"
},
{
"name": "Small Desktop",
"px": "768",
"cols": "9"
},
{
"name": "Desktop",
"px": "1024",
"cols": "12"
}
],
"order": 2,
"className": "",
"visible": true,
"disabled": false
},
{
"id": "6ffb10ff06c355be",
"type": "ui-base",
"name": "My Dashboard",
"path": "/dashboard",
"appIcon": "",
"includeClientData": true,
"acceptsClientConfig": [
"ui-notification",
"ui-control"
],
"showPathInSidebar": false,
"headerContent": "page",
"navigationStyle": "default",
"titleBarStyle": "default",
"showReconnectNotification": true,
"notificationDisplayTime": 1,
"showDisconnectNotification": true
},
{
"id": "6c7fce75833af206",
"type": "ui-theme",
"name": "Default Theme",
"colors": {
"surface": "#ffffff",
"primary": "#0094ce",
"bgPage": "#eeeeee",
"groupBg": "#ffffff",
"groupOutline": "#cccccc"
},
"sizes": {
"density": "default",
"pagePadding": "12px",
"groupGap": "12px",
"groupBorderRadius": "4px",
"widgetGap": "12px"
}
}
]
I appreciate your help.
Regards,
Zephyr