Advanced vue technology stack (06. State persistence, strict mode, two-way data binding problem)

Data persistence

In order to avoid the disappearance of the refreshed data, use plugin to achieve

Register the plugin globallyInsert picture description here
Then define this js

Insert picture description here

Strict mode

Add in the global store instance

strict: true

Modifying the value in the state by assignment will give an error .

If strict mode is turned on and you do not want to report an error in the production environment, you can judge the environment to perform strict mode inspection.
Insert picture description here

vue two-way binding problem (v-model)

如果在 vue 中用 v-modell 绑定 全局 store中 的state 值 会报错。

The first way

所以我们需要 把 语法塘 拆分成 绑定属性 与 监听事件 两个 函数 , 通过 store 规定的 mutations 来修改state 中 的值就不会报错

The second way

v-model 绑定一个 计算属性, 属性中如下定义, 这也是 语法糖的 是实现原理

Insert picture description here

Guess you like

Origin www.cnblogs.com/jackson1/p/12726337.html