小编new*_*mer的帖子

使用 nuxt auth 模块检测身份验证状态需要刷新

我的应用程序无法检测用户在未完全刷新页面的情况下登录时发生的状态更改。刷新后一切正常显示。我正在使用 Nuxt 及其包含的身份验证模块,这里记录了 - https://auth.nuxtjs.org/

这是无法检测状态变化的 v-if 语句:

  <template v-if="$auth.$state.loggedIn">
    <nuxt-link
      to="/profile"
    >
      Hello, {{ $auth.$state.user.name }}
    </nuxt-link>
  </template>
  <template v-else>
    <nuxt-link
      to="/logIn"
    >
      Sign In
    </nuxt-link>
  </template>
Run Code Online (Sandbox Code Playgroud)

这是我的登录页面中的登录方法。

  methods: {
    async onLogin() {
      try{

        this.$auth.loginWith("local", {
          data: {
            email: this.email,
            password: this.password
          }
        });

        this.$router.push("/");

      }catch(err){
        console.log(err);
      }

    }
  }
Run Code Online (Sandbox Code Playgroud)

我尝试通过计算属性获取状态,但得到了相同的结果。我可以看到 vuex 存储数据发生变化,表明我在 Chrome Dev Tools 的“应用程序”选项卡中正确登录/注销,但 Vue Dev 似乎不断表明我已登录......但不确定它是否只是错误。 .

注销时我也遇到了同样的问题。这是方法:

async onLogout() {
  try{
    await this.$auth.logout();
  }catch(err){
    console.log(err);
  }
}
Run Code Online (Sandbox Code Playgroud)

我很高兴提供更多细节。

vue.js vuex vuejs2 nuxt.js

6
推荐指数
1
解决办法
3708
查看次数

设置 Vuetify 应用栏扩展的颜色

我想更改 v-app-bar 扩展的颜色,使其与 v-app-bar 的颜色不同。文档中似乎没有任何内容,但我想这样一个简单的更改不会那么困难,而且很多人都想进行此更改。我尝试用CSS改变它,但没有成功。

  <v-app-bar
    app
    extensionHeight="35px"
    class="light-blue darken-4 px-2"
  >

    // This is the part I want to appear a separate color.
    <template 
      v-slot:extension
      class="extension-style"
    >
      <v-tabs align-with-title>
        <v-tab>Browsing History</v-tab>
        <v-tab>Todays Deals</v-tab>
        <v-tab>Your Store</v-tab>
        <v-tab>Gift Cards</v-tab>
        <v-tab>Registry</v-tab>
        <v-tab>Sell</v-tab>
      </v-tabs>
    </template>

  </v-app-bar>
Run Code Online (Sandbox Code Playgroud)

vue.js vuetify.js

4
推荐指数
1
解决办法
3455
查看次数

' - >'C的无效类型参数

我一直在收到错误

invalid type argument of '->' (have 'int') 
Run Code Online (Sandbox Code Playgroud)

在尝试从单独的函数中读取输入文件的内容时,我用箭头标记的行.

它保留在主程序中.我意识到它可能与指针有关但我无法解决它.

#include <stdio.h>
#include <stdlib.h>

void function1(file_a);

int main()
{

   FILE *file_a = fopen("input.txt", "r");

   if (file_a != NULL){

       void function1(file_a);
   }
   else{

   }

}

void function1(file_a)
{

   while(!feof (file_a)) <<<<<<<<
   {

   }

}
Run Code Online (Sandbox Code Playgroud)

c types

3
推荐指数
2
解决办法
135
查看次数

模拟类属性

我有一个带有单个类属性的类,我想模拟它

my_class.py

class MyClass:

    __attribute = ['123', '456']
Run Code Online (Sandbox Code Playgroud)

test_my_class.py

import pytest
from directory.my_class import MyClass

def test_1(mocker):
    with mocker.patch.object(MyClass, '__attribute', {'something': 'new'}):
        test = MyClass()
Run Code Online (Sandbox Code Playgroud)

我得到:

E           AttributeError: <class 'directory.my_class.MyClass'> does not have the attribute '__attribute'
Run Code Online (Sandbox Code Playgroud)

我在尝试时也遇到同样的错误:

def test_2(mocker):
    with mocker.patch('directory.my_class.MyClass.__attribute', new_callable=mocker.PropertyMock) as a:
        a.return_value = {'something': 'new'}
        test = MyClass()
Run Code Online (Sandbox Code Playgroud)

我还尝试了直接分配以及这篇文章中的其他建议: Better way to mock class attribute in python unit test

我的项目正在使用此插件中的模拟装置:https://pypi.org/project/pytest-mock/

python class mocking pytest

3
推荐指数
1
解决办法
6877
查看次数

unordered_set count 函数返回错误值

为什么有a时set.count('a')输出?13

程序:

bool isAnagram(string s, string t) {

    unordered_set<char> set;

    for(int i=0; i<s.size(); i++){
        set.insert(s[i]);
    }

    cout << endl << set.count('a') << endl;
    return false;
}
Run Code Online (Sandbox Code Playgroud)

输入:

s = 'anagram'
Run Code Online (Sandbox Code Playgroud)

输出:

1
Run Code Online (Sandbox Code Playgroud)

c++ unordered-map unordered-set

0
推荐指数
1
解决办法
127
查看次数

标签 统计

vue.js ×2

c ×1

c++ ×1

class ×1

mocking ×1

nuxt.js ×1

pytest ×1

python ×1

types ×1

unordered-map ×1

unordered-set ×1

vuejs2 ×1

vuetify.js ×1

vuex ×1