这是对这个问题的一个后续行动.
换句话说,问题2是:是否存在以下代码(在必要的语法中)起作用的语言:
def f(): print ('f')
def g():
f()
f = 42
g()
Run Code Online (Sandbox Code Playgroud) 我试图将实例data()中的值设置Vue为从调用返回的 Promise 中检索到的值mongodb api。我能够检索我正在尝试实现的数据,但是很难在现场使用它,data()以便我可以在模板中访问它。
我找到的一些解决方案似乎vue2在这种情况下不起作用。提前致谢。
维埃
<template>
<Article :title=posts[0].title></Article> // Another Vue component
</template>
let stories;
export default {
data() {
return {
posts: {}
}
},
methods: {
loadPosts() {
stories = getPosts(); // makes an api request to a mongodb that returns a Promise
stories.then(function(response) {
this.posts = response.posts;
console.log(response.posts[0].title); // "My Post Title"
});
}
},
mounted() {
this.loadPosts();
}
}
Run Code Online (Sandbox Code Playgroud)
我收到的错误说
未捕获(承诺中)类型错误:无法设置未定义的属性“帖子”
在参照this.posts = ...
据我所知,从文档和网上的几个帖子,声明
include("myfile.jl")
Run Code Online (Sandbox Code Playgroud)
只需获取myfile.jl中的代码并将其粘贴到调用文件(或控制台)中,用include语句替换该行.
如果我错了,请纠正我.我刚刚开始朱莉娅.但是,我还看到了朱莉娅的创作者之一的以下评论:
"include works in the dynamically-current module, not the lexically-current one.
It is really a load-time function, not a run-time one."
Run Code Online (Sandbox Code Playgroud)
动态电流和词汇电流有什么区别?