问题描述
我目前正在与支持Parse的Live Queries一起使用,并且我想在计算属性上使用此功能,以类似于Vuex中的mapGetters来使用它们。
检索初始值没有问题,但是由于更新是通过诸如here之类的Webhook事件推送的,因此我不知道如何更新Webhook设置的值。
我猜需要使用计算属性,因为我还需要set
方法来触发update logic。
我想实现一些功能,这些功能使我可以像使用普通v模型一样使用属性。
computed: {
...subParseDoc(['DocumentID','VariableName'],...)
}
我当前的方法如下所示,但是不支持更新对象,也不支持计算属性。
Vue.prototype.mountLiveQuery = function(id,target) {
let parts = id.split("/");
let parseObject = this.$parse.Object.extend(parts[0]);
let parseQuery = new this.$parse.Query(parseObject);
if (parts.length === 2) {
// mounting the whole class
parseQuery = parseQuery.equalTo("objectId",parts[1]);
parseQuery.first().then(object => this.$set(this,target,object));
parseQuery.subscribe().then(subscription => {
this.$options.beforeDestroy.push(() => subscription.unsubscribe());
subscription.on("update",object => this.$set(this,object));
subscription.on("delete",this.$set(this,null));
});
} else if (parts.length === 1) {
// mounting a single object / document
parseQuery.find().then(result => this.$set(this,result));
parseQuery.subscribe().then(subscription => {
this.$options.beforeDestroy.push(() => subscription.unsubscribe());
subscription.on("update",object => {
let newData = [...this[target]];
newData[newData.findIndex(el => el.id === object.id)] = object;
this[target] = newData;
});
subscription.on("create",object => {
this[target].push(object);
});
subscription.on("delete",object => {
this[target] = this[target].filter(el => el.id !== object.id);
});
});
}
};
任何有关如何实现这一目标的建议都将很不错!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)