Get the App
SLTechnology News&Howtos  ›  Development  › 

How to solve the error of Object.assign emptying Datagram in Vue

Shulou Source: shulou.com Published: 2022-06-01 09:32:21 09月21日 Update

This article mainly introduces the relevant knowledge of "how to solve Object.assign emptying data reporting errors in Vue". The editor shows you the operation process through actual cases. The operation method is simple, fast and practical. I hope this article "how to solve Object.assign emptying data reporting errors in Vue" can help you solve the problem.

The solution to the error of Object.assign emptying data report

If you want to clear the data Datagram error in Vue, maybe it is the reason why you did not change the this direction. You can try to change the this direction by using call and other conveniences.

For example:

Object.assign (this.$data, this.$options.data.call (this))

If you just want to make it clear that one of the pieces of data can be used

The assign method in this.xxx=this.$options.data.call (this) .xxxxObject

Object.assign ()

For object merging general merging const target = {avell} const source1 = {bvav 2} const source2 = {CRAV 3} Object.assign (target,source1,source2); console.log (target); / / {avell 1, bvl 2, cvv 3}

Be careful

The first parameter of the Object.assign () method is the target object, the remaining parameters are the original object, and all the original objects are merged into the target object.

That is, the original content of the first parameter will be changed.

If the destination object has an attribute with the same name as the source object, or if more than one source object has an attribute with the same name, the following properties override the previous properties.

The latter overrides the former: const target = {ARARO 1, BRV 1, CRAV 1} const source1 = {ARARO 2, BRV 2, CRAV 2} const source2 = {ARV 3, BRV 3, CRAV 3} Object.assign (target,source1,source2); console.log (target) / / {a: 3, b: 3, c: 3} Object.assign () has only one parameter

If this parameter is an object, it is returned directly.

Const target = {a target 1, b v v 1, c v v 1} console.log (Object.assign (target) = = target); / / true console.log (Object.assign (target) = target); / / trueObject.assign () has only one parameter

If the parameter is not an object, it is converted to an object and then returned.

Let x = Object.assign (123); console.log (typeof x); / / objectObject.assign () has only one parameter

Because undefined and null cannot be converted to objects, an error will be reported if they are used as parameters.

Object.assign (undefined) / / error Object.assign (null) / / error multiple parameters

If the non-object parameter appears at the location of the source object (that is, not the first parameter), the processing rules are different. First, these parameters are converted to objects, and if they cannot be converted to objects, they are skipped. This means that if undefined and null are not in the first parameter, no error will be reported.

Let obj = {a: 1}; Object.assign (obj, undefined) = obj / / trueObject.assign (obj, null) = obj / / true

Other types of values (that is, numeric, string, and Boolean values) are not in the first parameter and will not report an error. However, none of the values have any effect except that the string is copied into the target object as an array.

Const v1 = 'abc';const v2 = true;const v3 = 10 Const obj = Object.assign ({}, v1, v2, v3); console.log (obj) / / {"0": "a", "1": "b", "2": "c"} object merging is a shallow copy of var x = {"101": {" Score ": 50," Standards ": {}} var b = {" 101": {"Standards": {"11111": [11111]}} console.log (Object.assign ({}, xprib))

Guess what the result is.

{"101l": {"Standards": {"111": [0.2]}

This is the end of the content about "how to solve the error of Object.assign emptying Datagram in Vue". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Tags: Object parameter data attribute target only method knowledge different content multiple character copy point industry practical common clear that is location Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft NVidia Shulou Technology MariaDB macOS