Monitoring data using a change in the watch vue the deep: true, and immediate: true

In the project, sometimes detect whether the value of a variable rise has changed. watch commonly used or inefficient cycling determination. In times vue gives us a method for setting the depth of monitoring data prosperous change.

This is a use of a data vuex, settingData. Disabled in practice to be detected after the attribute value is changed to make a Button button removed. We can use a similar fashion, but this must be used when writing handler function.

There are immediate: true, will immediately execute the function handler inside after a statement on behalf watch inside. Performs corresponding logic. Without setting these properties may be used in a cyclic manner. 1. If an object is detected, the cycle time can be used to convert it into an array. (Simple Object Processing) 1. Object.keys (obj) of the object to put out a key array a.for ... in ... b. []. Slice.call (object) 2 then the cycle will use the corresponding value stored in another array. 3. The service logic then processing corresponding array

2. Use es6 way syntactic sugar

1.数组转对象
复制代码

2.对象转数组
    Array.from(object)
复制代码

Complex problem there is always a simple idea, a way to think and then write the code has encountered a problem.

Reproduced in: https: //juejin.im/post/5cf8787de51d4510aa0114c5

Guess you like

Origin blog.csdn.net/weixin_33813128/article/details/91459740