Contentful 不发起请求
Contentful doesn't initiate the request
我从 Contentful 开始,但出现此错误。
Import error, can't find file:
./zlib_bindings
我什么都没做,我只是按照文档中的描述发起了一个请求。
这是直到 componentDidMount
函数的代码。
我查看了 space ID 和访问令牌 in my application。
import React, { Component } from 'react';
import { render } from 'react-dom';
import contentful from 'contentful'
import './style.css';
import 'bulma/css/bulma.css'
import SearchComponent from './components/SearchComponent'
import ProductSection from './components/productSection'
class App extends Component {
constructor() {
super();
this.state = {
name: 'React'
};
}
componentDidMount() {
var client = contentful.createClient({
space: 'space_ID_here',
accessToken: 'access_here'
})
// This API call will request an entry with the specified ID from the space defined at the top, using a space-specific access token.
client.getEntries()
.then(function (entries) {
// log the title for all the entries that have it
entries.items.forEach(function (entry) {
if (entry.fields.productName) {
console.log(entry.fields.productName)
}
})
})
}
这很奇怪...我检查了 stackblitz link,它还要求安装 http
作为它不需要的依赖项。我几乎可以肯定 zlib_bindings
是 nothing related to the contentful sdk,但 Stackblitz 或您所在的环境中发生了其他事情 运行。
您可以在 React here.
中找到一个 运行 示例
我从 Contentful 开始,但出现此错误。
Import error, can't find file:
./zlib_bindings
我什么都没做,我只是按照文档中的描述发起了一个请求。
这是直到 componentDidMount
函数的代码。
我查看了 space ID 和访问令牌 in my application。
import React, { Component } from 'react';
import { render } from 'react-dom';
import contentful from 'contentful'
import './style.css';
import 'bulma/css/bulma.css'
import SearchComponent from './components/SearchComponent'
import ProductSection from './components/productSection'
class App extends Component {
constructor() {
super();
this.state = {
name: 'React'
};
}
componentDidMount() {
var client = contentful.createClient({
space: 'space_ID_here',
accessToken: 'access_here'
})
// This API call will request an entry with the specified ID from the space defined at the top, using a space-specific access token.
client.getEntries()
.then(function (entries) {
// log the title for all the entries that have it
entries.items.forEach(function (entry) {
if (entry.fields.productName) {
console.log(entry.fields.productName)
}
})
})
}
这很奇怪...我检查了 stackblitz link,它还要求安装 http
作为它不需要的依赖项。我几乎可以肯定 zlib_bindings
是 nothing related to the contentful sdk,但 Stackblitz 或您所在的环境中发生了其他事情 运行。
您可以在 React here.
中找到一个 运行 示例