有没有人可以帮我解决这个问题,我定义了一个有函数的模块,这个函数返回一个对象。当我调用这个函数时,对象被接收,但是当我想访问对象的状态元素时,表示未定义。
这是我的模块:
import firebaseapp from "./firebase";
import store from "../store/index";
const database = firebaseapp.firebase.database();
export default {
createProject(info) {
var result = {};
var userId = store.state.user.user.uid;
info.created_at = firebaseapp.firebase.database.ServerValue.TIMESTAMP;
info.status = "pendning";
info.ower = userId;
const project_ref = database.ref("/projects/" + userId + "/");
project_ref
.push()
.set(info)
.then(function() {
result.status = "1";
result.message = "successfully created";
})
.catch(function(error) {
result.status = "0";
result.message = error.message;
});
return result;
}
};
这是我要调用的模块
export default {
data() {
return {
result: {},
project: {
ideal_expert: {}
}
};
},
gotCreateProject() {
if (this.$refs.project_form.validate()) {
this.dialog = true;
this.result = create_project.createProject(this.project);
console.log(this.result); //the whole object
console.log(this.result.status);// the status property of object
} else {
this.dialog = false;
}
// console.log(this.dialog);
}
}
};
