Skip to content

Object passed into component.set is mutated by computed properties #479

@Conduitry

Description

@Conduitry

REPL

<script>
	export default {
		computed: {
			b: a => a + 1
		},
		oncreate() {
			let obj = { a: 1 };
			this.set( obj );
			console.log( obj );
		}
	}
</script>

This logs { a: 1, b: 2 }.

I have an app where I have an array of different objects that I pass to component.set as appropriate. The computed property is getting assigned into the object that's passed in. Calling component.set again with a previously used (and mutated) object is a problem when dev mode is enabled, because attempting to set the read-only computed property throws an error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions