Thanks, but this isn't working. Not sure what I'm doing wrong. The flow is below. If I inject the payload, it loads into the page. When the page loads, the function outputs the correct payload to a debug node. But, when loading the page the payload does not load
[{"id":"058ba9b7f3b37353","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"58a97cfca95999ff","type":"uibuilder","z":"058ba9b7f3b37353","name":"","topic":"","url":"home_config","fwdInMessages":false,"allowScripts":false,"allowStyles":false,"copyIndex":true,"templateFolder":"vue","extTemplate":"","showfolder":false,"useSecurity":false,"sessionLength":432000,"tokenAutoExtend":false,"reload":false,"sourceFolder":"src","credentials":{},"x":570,"y":260,"wires":[["0fa306891c3a3a1f"],["5e4a8ba26f24c4e1","5cd89f4b168a368d"]]},{"id":"0fa306891c3a3a1f","type":"debug","z":"058ba9b7f3b37353","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":790,"y":260,"wires":[]},{"id":"5e4a8ba26f24c4e1","type":"debug","z":"058ba9b7f3b37353","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":790,"y":320,"wires":[]},{"id":"5cd89f4b168a368d","type":"function","z":"058ba9b7f3b37353","name":"","func":"if (msg.uibuilderCtrl === \"ready for content\") {\n msg.payload = global.get('tbSN');\n return msg;\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":580,"y":400,"wires":[["58a97cfca95999ff","0b43a96346fd82c2"]]},{"id":"c921d4ccad028fbf","type":"inject","z":"058ba9b7f3b37353","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"tbSN","payloadType":"global","x":400,"y":340,"wires":[["58a97cfca95999ff"]]},{"id":"0b43a96346fd82c2","type":"debug","z":"058ba9b7f3b37353","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":880,"y":420,"wires":[]}]
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Home Configuration</title>
<link rel="icon" href="./images/node-blue.ico">
<link type="text/css" rel="stylesheet" href="../uibuilder/vendor/bootstrap/dist/css/bootstrap.min.css" />
<link type="text/css" rel="stylesheet" href="../uibuilder/vendor/bootstrap-vue/dist/bootstrap-vue.css" />
<!-- Your own CSS -->
<link type="text/css" rel="stylesheet" href="./index.css" media="all">
</head>
<body style="font-size:.9em" class="nr-dashboard-theme">
<h1>Home Configuration</h1>
<pre id="msg" class="syntax-highlight">Waiting for a message from Node-RED</pre>
<div id="app" v-cloak>
<b-container id="app_container" class="mt-5">
<div class="mt-5">
<b-table striped hover small :items="payload" sort-by="id"></b-table>
</div>
</b-container>
</div>
<!-- These MUST be in the right order. Note no leading / -->
<!-- REQUIRED: Socket.IO is loaded only once for all instances. Without this, you don't get a websocket connection -->
<script src="../uibuilder/vendor/socket.io/socket.io.js"></script>
<!-- Vendor Libraries - Load in the right order, use minified, production versions for speed -->
<script src="../uibuilder/vendor/vue/dist/vue.js"></script> <!-- dev version with component compiler -->
<!-- <script src="../uibuilder/vendor/vue/dist/vue.min.js"></script> prod version with component compiler -->
<!-- <script src="../uibuilder/vendor/vue/dist/vue.runtime.min.js"></script> prod version without component compiler -->
<script src="../uibuilder/vendor/bootstrap-vue/dist/bootstrap-vue.js"></script> <!-- Dev version -->
<!-- <script src="../uibuilder/vendor/bootstrap-vue/dist/bootstrap-vue.min.js"></script> Prod version -->
<!-- REQUIRED: Sets up Socket listeners and the msg object -->
<script src="./uibuilderfe.js"></script> <!-- dev version -->
<!-- <script src="./uibuilderfe.min.js"></script> prod version -->
<!-- OPTIONAL: You probably want this. Put your custom code here -->
<script src="./index.js"></script>
</body>
</html>
var app = new Vue({
// The HTML element to attach to
el: '#app',
data() {
return {
payload: [] // table data
};
}, // --- End of data --- //
computed: {}, // --- End of computed --- //
methods: {}, // --- End of methods --- //
// Available hooks: beforeCreate,created,beforeMount,mounted,beforeUpdate,updated,beforeDestroy,destroyed, activated,deactivated, errorCaptured
// Called after the Vue app has been created. A good place to put startup code
created: function() {
// **REQUIRED** Start uibuilder comms with Node-RED
uibuilder.start()
},
// Called when Vue is fully loaded
mounted: function() {
// Keep a convenient reference to the Vue app
var vueApp = this
/** Triggered when the node on the Node-RED server
* recieves a (non-control) msg
*/
uibuilder.onChange('msg', function(msg) {
vueApp.payload = msg.payload; // this is what grabs the msg.payload when injected to UI_Builder
})
// Send message back to node-red
// uibuilder.send({payload:'some message'})
},
}) // --- End of the Vue app definition --- //