fix(flow): props not being watched on time
* updated example for UpdateNode Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
@@ -10,9 +10,11 @@ const initialElements: Elements = [
|
||||
]
|
||||
|
||||
const elements = ref<Elements>(initialElements)
|
||||
const nodeName = ref<string>('Node 1')
|
||||
const nodeBg = ref<string>('#eee')
|
||||
const nodeHidden = ref<boolean>(false)
|
||||
const opts = ref({
|
||||
bg: '#eee',
|
||||
name: 'Node 1',
|
||||
hidden: false,
|
||||
})
|
||||
|
||||
const updateNode = () => {
|
||||
elements.value = elements.value.map((el) => {
|
||||
@@ -20,29 +22,30 @@ const updateNode = () => {
|
||||
// it's important that you create a new object here in order to notify react flow about the change
|
||||
el.data = {
|
||||
...el.data,
|
||||
label: nodeName.value,
|
||||
label: opts.value.name,
|
||||
}
|
||||
el.style = { backgroundColor: nodeBg.value }
|
||||
el.isHidden = nodeHidden.value
|
||||
el.style = { backgroundColor: opts.value.bg }
|
||||
el.isHidden = opts.value.hidden
|
||||
}
|
||||
|
||||
return el
|
||||
})
|
||||
}
|
||||
|
||||
onMounted(updateNode)
|
||||
</script>
|
||||
<template>
|
||||
<VueFlow v-model="elements" :default-zoom="1.5" :min-zoom="0.2" :max-zoom="4">
|
||||
<div class="updatenode__controls">
|
||||
<label>label:</label>
|
||||
<input v-model="nodeName" @input="updateNode" />
|
||||
<input v-model="opts.name" @input="updateNode" />
|
||||
|
||||
<label class="updatenode__bglabel">background:</label>
|
||||
<input v-model="nodeBg" type="color" @input="updateNode" />
|
||||
<input v-model="opts.bg" type="color" @input="updateNode" />
|
||||
|
||||
<div class="updatenode__checkboxwrapper">
|
||||
<label>hidden:</label>
|
||||
<input v-model="nodeHidden" type="checkbox" @input="updateNode" />
|
||||
<input v-model="opts.hidden" type="checkbox" @change="updateNode" />
|
||||
</div>
|
||||
</div>
|
||||
</VueFlow>
|
||||
|
||||
Reference in New Issue
Block a user