1. 安装 vue-router:yarn add vue-router@next
  2. 安装 vuex:yarn add vuex@next
  3. 安装 axios:yarn add axios
  4. 配置 webpack:在 webpack.config.js 中配置 alias,如下所示:
const path = require('path');

module.exports = {
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src'),
    },
  },
};
  1. 配置 babel:在 babel.config.js 中添加 vue-jsx 插件,如下所示:
module.exports = {
  presets: [
    '@babel/preset-env',
    '@vue/babel-preset-app'
  ],
  plugins: [
    ['@vue/babel-plugin-jsx', { transformOn: true }]
  ]
}
  1. 配置 eslint:在 .eslintrc.js 中添加以下配置,如下所示:
module.exports = {
  extends: [
    'plugin:vue/vue3-essential',
    'eslint:recommended',
    '@vue/typescript/recommended'
  ],
  plugins: ['@typescript-eslint'],
  parserOptions: {
    ecmaVersion: 2020
  },
  env: {
    browser: true,
    node: true,
  },
  rules: {
    // add your custom rules here
  }
}
  1. 按需加载 Vant 组件(如需要):安装 Vant 并按需加载组件,具体步骤可参考 Vant 官方文档。

以上是搭建 Vue3 项目后需要配置的一些常用环境和插件,根据具体需求可酌情添加。

Vue3 项目搭建后配置指南:路由、状态管理、网络请求等

原文地址: https://www.cveoy.top/t/topic/oBfV 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录