我有一个很长时间都无法解决的问题,我用feathersJS作为后台api,前台用Vue.js和Mongodb做了一个商店。当我试图在网站上验证用户时,一切都很顺利,直到 "setUser "动作启动,在auth服务获取器中,我得到一个错误,说 "不能读取属性'idField'的undefined"。我相信我已经尽可能的将这个属性改成了"_id",但还是出现了这个错误。这里有一些截图,可能会有帮助。这个项目应该是我在webDev的第一份工作,所以我将永远感激你的支持。
Feathers-client.js。
import feathers from '@feathersjs/feathers';
import socketio from '@feathersjs/socketio-client';
import auth from '@feathersjs/authentication-client';
import io from 'socket.io-client';
import { iff, discard } from 'feathers-hooks-common';
import feathersVuex from 'feathers-vuex';
const socket = io('http://localhost:3030', { transports: ['websocket'] });
const feathersClient = feathers()
.configure(socketio(socket))
.configure(auth({ storage: window.localStorage, debug: false }))
.hooks({
before: {
all: [
iff(
context => ['create', 'update', 'patch'].includes(context.method),
discard('__id', '__isTemp'),
),
],
},
});
export default feathersClient;
// Setting up feathers-vuex
const {
makeServicePlugin, makeAuthPlugin, BaseModel, models, FeathersVuex,
} = feathersVuex(
feathersClient,
{
idField: '_id', // Must match the id field in your database table/collection
whitelist: ['$regex', '$options'],
},
);
export {
makeAuthPlugin, makeServicePlugin, BaseModel, models, FeathersVuex,
};
js: auth服务文件:
import { makeAuthPlugin } from '../../feathers-client';
export default makeAuthPlugin({
userService: 'api/users',
entityIdField: '_id',
});
这里的问题是服务的名称,作为vuex的插件,服务的名称是 "users "而不是 "apiusers"。解决的办法是在servicePlugin选项中修改nameStyle. "路径 "而不是 "短"。"path "而不是 "short"