- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想从 hug 服务器到 vue 客户端从 localhost API 获取数据。我在 vue.js 中有这段代码:
<div id="aplicacio">
{{ documents }}
<ul>
<li v-for="document in documents">
<a v-bind:href="document.path">{{ document.title }}</a>: {{document.text}}
</li>
</ul>
</div>
<script>
var app = new Vue({
el: '#aplicacio',
data: {
documents: []
},
created () {
fetch('http://localhost:8000/documents/list')
.then(response => response.json())
.then(json => {
this.documents = json.documents
})
}
})
</script>
拥抱这段代码:
import hug
api = hug.API(__name__)
api.http.add_middleware(hug.middleware.CORSMiddleware(api, max_age=100))
@hug.get('/documents/list')
def list():
"""Returns list of documents"""
j = [{"text": "Hola", "path": "normativa.md", "title": "Normativa"}, {"text": "Això és una *activitat*", "path": "activitat1.md", "title": "Activitat 1"}]
return j
我咨询的时候莫名其妙applicacio.documents
在 firefox 控制台中,它让我得到 undefined
.这不是 CORS 问题,因为我添加了 api.http.add_middleware(hug.middleware.CORSMiddleware(api, max_age=100))
在后端和<meta http-equiv="Content-Security-Policy" content="" />
在网页中。
最佳答案
您可能需要检查您的 api 响应。
特别是如果它在其 json 负载中具有属性“文档”。
.then(json => {
// are we sure json includes a property documents?
// maybe json is the array itself
console.log(json)
this.documents = json.documents
})
关于javascript - 在拥抱服务器中进行 CORS 咨询后,Vue.js 返回未定义的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59021832/
在 GHCi 中,以下代码可以正常工作: f1 :: Float f1 = f2 -- f2 :: Float f2 = 1/1 但是在 Hugs 中,我得到了一个类型错误——它想成为一个 Doubl
拥抱似乎有几个不抱的问题!!在部分应用程序中。 虽然这在 GHCi 中运行良好: ([[0]]!!0!!)0 Hugs 报告 ) 的语法错误。 . 这是拥抱中的错误吗? 为第二个列表索引运算符添加一个
我有一个输入: [ 8 `div` 2 + 1 .. ] !! 2 : [ 1 .. 3 ] 输出为: [7,1,2,3] 但是.. Haskell首先计算什么? 我不知道优先级,哪七个是哪里来的
初识 .NET 2016 .NET 2016 概览 .NET 2016 作为 .NET 技术最新发展,如下图所示,它主要包含三大块: 最左边代表的是 .NET Framework 4.6,WP
关闭。这个问题需要更多 focused .它目前不接受答案。 想改进这个问题?更新问题,使其仅关注一个问题 editing this post . 4年前关闭。 Improve this questi
我是一名优秀的程序员,十分优秀!