我正在为Pocket/CouchDB开发一个Vue插件,该插件将是开源的,但只要我能找出一个问题,我就会:
目前,我正在try 使插件与Vuex非常相似,它有一个内部状态,可以检测更改,并在发生更改时呈现视图.
在Vue实例中,我正在初始化一个对象,在该对象中,我试图使两个或三个对象处于活动状态,使用defineReactive,直到这里一切正常.
但当我试图更改该对象内的某些值时,这些更改不会传播到视图.但如果我显式地调用this.$bucket._state.projects.__ob__.dep.notify(),这些变化就会传播.
Vue实例的当前对象表示形式如下:Vue { $bucket: { _state: { projects: {} } } }
$bucket._state
已初始化为defineReactive
.我相信它应该会起作用,但我不确定这件事的确切问题是什么.
知道吗?
代码的一部分,这里的类几乎类似于Vuex.Store({})
constructor(schema = {}) {
// Getting defineReactive from Vue
const { defineReactive } = Vue.util;
// Ignored Schema Keys
const ignoredKeys = [
'config',
'plugins'
];
// Internal Variables
this._dbs = {};
// Define Reactive Objects
defineReactive(this, '_state', {});
defineReactive(this, '_views', {});
// Local Variables
if (!schema.config) {
throw new Error(`[Pouch Bucket]: Config is not declared in the upper level!`);
}
// Init PouchDB plugins
if ((schema.plugins.constructor === Array) && (schema.plugins.length > 0)) {
for (let i = 0; i < schema.plugins.length; i++) {
PouchDB.plugin(
schema.plugins[i]
);
}
}
// Initializing DBs that are declared in the schema{}
for (const dbname in schema) {
if (schema.hasOwnProperty(dbname) && ignoredKeys.indexOf(dbname) === -1) {
this._initDB(
dbname,
Object.assign(
schema.config,
schema[dbname].config ? schema[dbname].config : {}
)
);
this._initState(dbname);
}
}
}