在vuejs3下安装vee-validate出现错误

mst*_*std 1 vee-validate vuejs3

在 vuejs3 下我使用命令安装 vee-validate

yarn add vee-validate@next
Run Code Online (Sandbox Code Playgroud)

成功后我运行服务器并出现错误

$ yarn run serve            
yarn run v1.22.5
$ vue-cli-service serve
 INFO  Starting development server...
98% after emitting CopyPlugin
ERROR  Failed to compile with 1 errors                                                                                                                                                                   
    2:07:01 PM

This dependency was not found:

* vee-validate/dist/rules in ./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader-v16/dist??ref--0-1!./src/components/auth/Login.vue?vue&type=script&lang=js

To install it, you can run: npm install --save vee-validate/dist/rules
Error from chokidar (/mnt/_work_sdb8/wwwroot): Error: Circular symlink detected: "/mnt/_work_sdb8/wwwroot/wwwroot" points to "/mnt/_work_sdb8/wwwroot"
Run Code Online (Sandbox Code Playgroud)

我将 vuejs 2 应用程序中的代码粘贴为:

<script>
  import { bus } from '../../../src/main'
  import appMixin from '@/appMixin'

  import { ValidationObserver, ValidationProvider, extend } from 'vee-validate'
  import * as rules from 'vee-validate/dist/rules'

  Object.keys(rules).forEach(rule => {
    extend(rule, rules[rule])
  })

  export default {
    name: 'loginPage',
    mixins: [appMixin],

    components: {
      ValidationObserver,
      ValidationProvider
    },
Run Code Online (Sandbox Code Playgroud)

但是在这里阅读https://github.com/logaretm/vee-validate 我没有看到我必须应用 vuejs 3 是否有一些语法更改?

package.json:
{
  "name": "yt3",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint"
  },
  "dependencies": {
    "axios": "^0.20.0-0",
    "core-js": "^3.6.5",
    "mitt": "^2.1.0",
    "moment-timezone": "^0.5.31",
    "node-sass": "^4.12.0",
    "sass-loader": "^10.0.4",
    "vee-validate": "^4.0.0-beta.16",
    "vue": "^3.0.0",
    "vue-router": "^4.0.0-rc.1",
    "vuex": "^4.0.0-rc.1"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "~4.5.0",
    "@vue/cli-plugin-eslint": "~4.5.0",
    "@vue/cli-service": "~4.5.0",
    "@vue/compiler-sfc": "^3.0.0",
    "@vue/eslint-config-standard": "^5.1.2",
    "babel-eslint": "^10.1.0",
    "eslint": "^6.7.2",
    "eslint-plugin-import": "^2.20.2",
    "eslint-plugin-node": "^11.1.0",
    "eslint-plugin-promise": "^4.2.1",
    "eslint-plugin-standard": "^4.0.0",
    "eslint-plugin-vue": "^7.0.0-0"
  },
  "eslintConfig": {
    "root": true,
    "env": {
      "node": true
    },
    "extends": [
      "plugin:vue/essential",
      "eslint:recommended"
    ],
    "parserOptions": {
      "parser": "babel-eslint"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

修改块: 我添加了行

 "vee-validate": "^3.1.0" 
Run Code Online (Sandbox Code Playgroud)

在 package.json 文件中并运行命令

 yarn
Run Code Online (Sandbox Code Playgroud)

 yarn run serve
Run Code Online (Sandbox Code Playgroud)

我在浏览器控制台中收到错误:

vee-validate.esm.js?7bb1:867 Uncaught TypeError: vue__WEBPACK_IMPORTED_MODULE_0__.default is not a constructor
    at eval (vee-validate.esm.js?7bb1:867)
    at Module../node_modules/vee-validate/dist/vee-validate.esm.js (chunk-vendors.js:3389)
    at __webpack_require__ (app.js:849)
    at fn (app.js:151)
    at eval (cjs.js?!./node_modules/babel-loader/lib/index.js!./node_modules/cache-loader/dist/cjs.js?!./node_modules/vue-loader-v16/dist/index.js?!./src/components/auth/Login.vue?vue&type=script&lang=js:10)
    at Module../node_modules/cache-
Run Code Online (Sandbox Code Playgroud)

看起来 vee-validate 3 和 vuejs 3 不兼容?
您建议使用哪些 vuejs 3 验证工具?

谢谢!

Mic*_*evý 5

关于版本 4 的Github 迁移指南问题的一些评论:

  • 由于API完全不同,没有直接升级途径
  • 甚至让人们知道 v4 适用于 Vue 3 而 v3 适用于 Vue2 对人们来说也是有用的

SO:V4 仅vee-validate适用于 Vue 3,并且具有与 V3 非常不同的 API(仅适用于 Vue 2)

另外,从V4 指南来看,他们似乎决定放弃内置验证器,转而使用像yup这样的专门库

因此,使用现有 Vue 2 应用程序中的任何代码没有任何意义 - 如果您使用的是 Vue 3:

  • vee-validate:使用 V4 的指南并使用新的 API 再次编写代码......
  • 做好准备,许多已建立的库还没有Vue 3 的稳定版本......这就是我在任何严肃项目上都在 Vue 2 上停留至少 6 个月的原因(同时使用 Vue 3)