小编Gil*_*mes的帖子

“在查询中找到@client指令,但未指定客户端解析器”使用客户端缓存时警告

我一直在关注本地状态的Apollo Client文档

我实现了一个非常简单的客户端缓存查询:

export const GET_USER_ACCOUNTS = gql`
    query GetUserAccounts {
        userAccounts @client
        name @client
    }
`;
Run Code Online (Sandbox Code Playgroud)

userAccountsname在身份验证后都存储在我的缓存中:

export const GET_USER_ACCOUNTS = gql`
    query GetUserAccounts {
        userAccounts @client
        name @client
    }
`;
Run Code Online (Sandbox Code Playgroud)

并且我已经使用默认值预热了缓存:

import { ApolloClient } from 'apollo-client';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { HttpLink } from 'apollo-link-http';

const cache = new InMemoryCache();
const link = new HttpLink({
    uri: 'http://localhost:8002/v1/graphql',
    headers: {
        Authorization: `${localStorage.getItem('token')}`,
    },
});
const client = new ApolloClient({
    cache, …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs graphql apollo-client

10
推荐指数
2
解决办法
2940
查看次数

有没有办法将Angular 2属性指令传递给函数

在Angular 1中,您可以使用&将函数作为参数传递给属性指令.我知道你可以使用函数将函数作为输入传递给Angular 2中的元素指令(组件)

<custom-component [callback]="myCallbackFuncton">
..etc
</custom-component>
Run Code Online (Sandbox Code Playgroud)

语法,但有没有办法只使用属性指令?我只能得到一个字符串(它允许我在范围内查看该函数),但更愿意一次性传递该函数.所以我希望能够在我的模板中写出这样的东西

 <form custom-submit="ctrl.register">
 ...etc
 </form>
Run Code Online (Sandbox Code Playgroud)

并在指令js中,

@Directive({
    selector: '[custom-submit]',
})
@Inject('$element', '$attrs')

export default class CustomSubmit {
    constructor($element, $scope, $attrs) {
        this.$element = $element;

        $element[0].addEventListener('submit', () => {
          // custom validation behaviour
          $attrs.customSubmit();
        });
   }
}
Run Code Online (Sandbox Code Playgroud)

而不是必须写像

 $scope.ctrl[$attrs.customSubmit]()
Run Code Online (Sandbox Code Playgroud)

angularjs angular2-directives angular

2
推荐指数
1
解决办法
6333
查看次数