How to update edge property ("animated") dynamically? #934
-
First, Thanks for your amazing work and extremely well-maintained library. Well, I am using custom edge component having few custom properties which are getting updated dynamically. To allow enabling animated line style dynamically by user, would be looking at updating this property (default value is false). Any attempt to set this property leading to error - "set operation on key "animated" failed: target is readonly. ". While custom properties managed through "data" key are working fine, requesting your guidance to update "animated" property. Context:
Though vue-flow is listening for 'edge-update' and updating the edge, how that can be triggered here? I did see EdgeUpdateEvent in document guide however have not found way to use/trigger it. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Props are readonly (this is imposed by Vue, read this section of the Vue docs) so trying to modify props will not work, that's why you get the error you quoted. There's a couple of ways of going about this but the simplest way is to use the edge object from the store state directly and mutate it. // from inside your edge component
const { edge } = useEdge()
// or
const { findEdge } = useVueFlow()
const edge = findEdge(id)
function toggleAnimate() {
edge.animated = !edge.animated
} |
Beta Was this translation helpful? Give feedback.
Props are readonly (this is imposed by Vue, read this section of the Vue docs) so trying to modify props will not work, that's why you get the error you quoted.
There's a couple of ways of going about this but the simplest way is to use the edge object from the store state directly and mutate it.