Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error 'submitForm' is assigned a value but never used. but 'submitForm' is used in template #2507

Open
StrongerLph opened this issue Jul 11, 2024 · 0 comments

Comments

@StrongerLph
Copy link

Checklist

  • [√ ] I have tried restarting my IDE and the issue persists.
  • [√ ] I have read the FAQ and my problem is not listed.

Tell us about your environment

  • ESLint version: 9.6.0
  • eslint-plugin-vue version: 9.27.0
  • Vue version: 3.4.21
  • Node version: v18.16.0
  • Operating System: windows

Please show your full configuration:

import globals from 'globals';
import pluginJs from '@eslint/js';
import tseslint from 'typescript-eslint';
import pluginVue from 'eslint-plugin-vue';
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
import { FlatCompat } from '@eslint/eslintrc';
import path from 'path';
import { fileURLToPath } from 'url';

// mimic CommonJS variables -- not needed if using CommonJS
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const compat = new FlatCompat({
  baseDirectory: __dirname,
});

export default [
  {
    files: ['**/*.{js,jsx,mjs,cjs,ts,tsx,vue}'],
    ignores: ['.vscode', '.husky', '**/node_modules/', 'dist', 'dist-electron'],
    languageOptions: {
      parser: 'vue-eslint-parser',
      parserOptions: {
        parser: '@typescript-eslint/parser',
        ecmaVersion: 'latest',
        sourceType: 'module',
        ecmaFeatures: {
          jsx: true,
        },
      },
      globals: { ...globals.browser, ...globals.node },
    },
  },
  pluginJs.configs.recommended,
  ...tseslint.configs.recommended,
  ...pluginVue.configs['flat/essential'],
  ...compat.extends('eslint-config-standard'),
  ...compat.extends('./.eslintrc-auto-import.json'),
  eslintPluginPrettierRecommended,
  {
    rules: {
      '@typescript-eslint/no-explicit-any': 'off',
      'vue/multi-word-component-names': 0,
    },
  },
];

What did you do?

<!-- eslint-disable no-irregular-whitespace -->
<template>
  <div class="register-container">
    <el-card class="register-card">
      <el-form ref="registerFormRef" :model="registerForm" :rules="registerFormRules" label-width="100px">
        <el-form-item label="用户名" prop="username">
          <el-input v-model="registerForm.username"></el-input>
        </el-form-item>
        <el-form-item label="密 码" prop="password">
          <el-input type="password" v-model="registerForm.password"></el-input>
        </el-form-item>
        <el-form-item label="邮 箱" prop="email">
          <el-input v-model="registerForm.email"></el-input>
        </el-form-item>
      </el-form>
      <div class="register-form-btns">
        <el-button type="primary" @click="submitForm">注 册</el-button>
        <el-button @click="backToLogin">返回登录</el-button>
      </div>
    </el-card>
  </div>
</template>

<script setup lang="ts">
import router from '@/router';
import { UserRegisterType, register } from '@/api/user';
import type { FormInstance, FormRules } from 'element-plus';

const registerFormRef = ref<FormInstance>();

const registerForm = ref<UserRegisterType>({
  username: '',
  password: '',
  email: '',
});

const registerFormRules: FormRules<UserRegisterType> = {
  email: [
    { required: true, message: '请输入邮箱账号', trigger: 'blur' },
    { type: 'email', message: '请输入正确的邮箱格式', trigger: 'blur' },
  ],
  username: [
    { required: true, message: '请输入用户名', trigger: 'blur' },
    { min: 3, max: 10, message: '长度在 3 到 10 个字符', trigger: 'blur' },
  ],
  password: [
    { required: true, message: '请输入密码', trigger: 'blur' },
    { min: 6, max: 20, message: '长度在 6 到 20 个字符', trigger: 'blur' },
  ],
};

const submitForm = async () => {
  registerFormRef.value?.validate(async (valid: boolean) => {
    if (!valid) return;
    await register(registerForm.value);
  });
};

const backToLogin = () => {
  router.replace('/login');
};
</script>

<style lang="scss" scoped>
.register-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;

  .register-card {
    width: 400px;

    .register-form-btns {
      display: flex;
      flex-direction: column;
      align-items: center;
      margin-top: 20px;

      .el-button {
        width: 100px;
      }

      .el-button:last-child {
        margin-top: 10px;
        margin-left: 0;
      }
    }
  }
}
</style>

What did you expect to happen?
Correctly identify whether the variable has been referenced

What actually happened?

image

Repository to reproduce this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant