Skip to content

Instantly share code, notes, and snippets.

@Manyaka
Last active July 9, 2019 02:40
Show Gist options
  • Save Manyaka/314eb815c7304cf76aa4dab52898a5f4 to your computer and use it in GitHub Desktop.
Save Manyaka/314eb815c7304cf76aa4dab52898a5f4 to your computer and use it in GitHub Desktop.
Три способа получить пустой объект во Vue.js, потому что, из-за системы реактивности, в объект приезжают свойства от Observer.
props: {
someObject: {
type: Object,
default: () => ({}),
},
},
created() {
console.log(this.someObject); // {__ob__: Observer}
let variant1 = JSON.parse(JSON.stringify(this.someObject));
console.log(variant1); // {}
let variant2 = { ...this.someObject };
console.log(variant2); // {}
let variant3 = Object.assign({}, this.someObject);
console.log(variant3); // {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment