关于store._vm

来源:12-10 Vuex 初始化(9)

慕粉4283821

2021-01-15

老师 ,为什么要在store 上定义一个_vm实例, 只是为了做警告吗。

// use a Vue instance to store the state tree
// suppress warnings just in case the user has added
// some funky global mixins
const silent = Vue.config.silent
Vue.config.silent = true
store._vm = new Vue({
  data: {
    $$state: state
  },
  computed
})
Vue.config.silent = silent

// enable strict mode for new vm
if (store.strict) {
  enableStrictMode(store)
}
写回答

1回答

ustbhuangyi

2021-01-15

这里主要是为了把 state 变成响应式吧,这样修改了 state 的数据,使用到的组件才能自动更新。

0
1
慕粉4283821
非常感谢!
2021-01-16
共1条回复

Vue.js 源码深入解析 深入理解Vue实现原理

全方位讲解 Vue.js 源码,进阶高级工程师

4984 学习 · 1037 问题

查看课程