我正在使用我想在我的 React-Redux-Webpack 应用程序的操作中导入的 ES6 类设置一个羽毛客户端。
我已经使用很棒的 Feathers 脚手架设置了一个 REST api。
不幸的是,我在浏览器中遇到了一个错误,这毁了我的一天。我究竟做错了什么?
未捕获的 TypeError:_client2.default.hooks 不是函数
谁能帮我吗?为什么hooks
(也rest
)在这里未定义?软件包似乎已正确安装...
以下是个好主意吗?
// src/middleware/api.js
import hooks from 'feathers-hooks'
import feathers from 'feathers/client'
import rest from 'feathers-rest/client'
class API {
constructor() {
const connection = process.env.FEATHERS_API_URL
this.app = feathers()
.configure(feathers.hooks())
.configure(rest(connection).fetch(fetch))
.configure(feathers.authentication({
type: 'local',
storage: window.localStorage,
}))
}
}
会不会是某些包不兼容?
"feathers": "^2.0.3",
"feathers-authentication": "^0.7.12",
"feathers-client": "^1.8.0",
"feathers-configuration": "^0.3.3",
"feathers-errors": "^2.5.0",
"feathers-hooks": "^1.7.1",
"feathers-rest": "^1.5.2",
"feathers-sequelize": "^1.4.0"
我想知道的另一件事是我们是否总是需要为rest
函数提供路径?可以默认使用配置文件中使用的路径吗?让我的客户端和服务器端代码在同一个项目中,给它提供一条路径感觉有点奇怪......