此文件初始化Parse并导出已定义的Parse对象:
store.js
import Parse from 'parse'
Parse.initialize('APP_ID', 'CLIENT_ID')
const ParseProject = Parse.Object.extend('Project')
var Project = new ParseProject()
var Query = new Parse.Query(ParseProject)
export {
Project,
Query
}
这个使用这些对象来执行保存操作。
main.js:
import {Project, Query} from '../store'
export default {
submit () {
const project = {
title: this.title,
content: this.content
}
Project.save(project).then((result) =>
console.log('Success:', result)
)
}
}
它可以工作,但每次都保存相同的对象(我的应用程序是单页面应用程序,没有重新加载)。
因此,如果您多次点击submit()
:
ParseObjectSubclass {className: "Project", _objCount: 0, id: "vIqpMEUPyD"}
ParseObjectSubclass {className: "Project", _objCount: 0, id: "vIqpMEUPyD"}
ParseObjectSubclass {className: "Project", _objCount: 0, id: "vIqpMEUPyD"}
如何导入那些Parse对象,以便每次都创建一个不同的Parse对象?
答案 0 :(得分:1)
这取决于模块的内部如何使用Project
的保存状态,但如果我需要在保存前每次创建一个新实例,我会使用:
<强> store.js 强>
let ProjectFactory = () => new ParseProject()
<强> main.js 强>
let saved_project // define in the scope where it's needed to be used
submit () {
saved_project = ProjectFactory().save(project)...
}