小编Dan*_*eij的帖子

开玩笑地监视模块功能

我正在用玩笑编写测试,其中我想监视一些 lodash 函数,我在模块中单独导入这些函数(而不是将整个 lodash 模块导入为_),例如

/** matrix.js **/
import shuffle from 'lodash/shuffle'
import pick from 'lodash/pick'

// ...

/**
 * Shuffles the order of the rows in the matrix. If a column/variable name
 * is specified, only the rows in this column are shuffled.
 *
 * @export
 * @param {array} matrix The matrix to be shuffled
 * @param {array} columns  Array containing the variable/column to be shuffled
 * @returns {array}
 */
export function shuffleVert (matrix, columns) {
  if …
Run Code Online (Sandbox Code Playgroud)

javascript unit-testing lodash jestjs es6-modules

10
推荐指数
1
解决办法
1万
查看次数

使用Laravel为后端刷新Vue.js SPA的身份验证令牌

我使用Laravel(5.5)作为后端,使用Vue(2.5)构建单页应用程序.一切正常,除了在退出后再次直接登录.在这种情况下,对/ api/user的调用(以检索用户的帐户信息并再次验证用户的身份)失败,401未经授权(即使登录成功).作为回应,用户直接退回到登录屏幕(我自己写了这个措施作为对401响应的反应).

注销是什么,用ctrl/cmd + R刷新页面,然后再次登录.一个页面刷新解决我的问题,这一事实让我有理由相信,我不处理X-CSRF-TOKEN的刷新正确,也可以忘掉那Laravel使用某些cookie(如描述在这里).

这是在用户单击登录按钮后执行的登录表单代码的片段.

login(){
    // Copy the form data
    const data = {...this.user};
    // If remember is false, don't send the parameter to the server
    if(data.remember === false){
        delete data.remember;
    }

    this.authenticating = true;

    this.authenticate(data)
        .then( this.refreshTokens )
        .catch( error => {
            this.authenticating = false;
            if(error.response && [422, 423].includes(error.response.status) ){
                this.validationErrors = error.response.data.errors;
                this.showErrorMessage(error.response.data.message);
            }else{
                this.showErrorMessage(error.message);  
            }
        });
},
refreshTokens(){
    return new Promise((resolve, reject) => {
        axios.get('/refreshtokens')
            .then( response => {
                window.Laravel.csrfToken = response.data.csrfToken;
                window.axios.defaults.headers.common['X-CSRF-TOKEN'] …
Run Code Online (Sandbox Code Playgroud)

php jwt laravel single-page-application vue.js

7
推荐指数
1
解决办法
3471
查看次数