### Getting Started with vue-element-admin Development Source: https://panjiachen.github.io/vue-element-admin-site/index Instructions to clone the vue-element-admin project, install its dependencies using npm, and start the local development server. ```Bash # clone the project git clone https://github.com/PanJiaChen/vue-element-admin.git # install dependency npm install # develop npm run dev ``` -------------------------------- ### Getting Started with Vue Element Admin Development Source: https://panjiachen.github.io/vue-element-admin-site/guide Provides a sequence of shell commands to clone the Vue Element Admin repository, navigate into the project directory, install dependencies, and start the development server. ```Shell # clone the project git clone https://github.com/PanJiaChen/vue-element-admin.git # enter the project directory cd vue-element-admin # install dependency npm install # develop npm run dev ``` -------------------------------- ### Install lint-staged Development Dependency Source: https://panjiachen.github.io/vue-element-admin-site/es/guide/advanced/git-hook Command to install `lint-staged` as a development dependency using npm, which is essential for setting up pre-commit hooks in a project. ```Shell npm install lint-staged -D -S ``` -------------------------------- ### Install Husky npm package Source: https://panjiachen.github.io/vue-element-admin-site/es/guide/advanced/git-hook Command to install the husky package as a development dependency using npm. This enables Git hooks to be configured for pre-commit checks. ```bash npm install husky -D -S ``` -------------------------------- ### JavaScript File Naming Convention (kebab-case) Source: https://panjiachen.github.io/vue-element-admin-site/guide/advanced/style-guide Illustrates the kebab-case naming convention for all .js files within the project. This ensures consistency across utility and helper scripts. ```File Path @/utils/open-window.js @/views/svg-icons/require-icons.js @/components/MarkdownEditor/default-options.js ``` -------------------------------- ### PostCSS Autoprefixer Configuration with Browserslist Source: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/style Illustrates the configuration of Autoprefixer within 'postcss.config.js' and its integration with the 'browserslist' array defined in 'package.json' for managing browser compatibility. ```JavaScript // postcss.config.js module.exports = { plugins: { autoprefixer: {} } } ``` ```JSON "browserslist": [ "> 1%", "last 2 versions", "not ie <= 8" ] ``` -------------------------------- ### Install element-theme global CLI Source: https://panjiachen.github.io/vue-element-admin-site/guide/advanced/theme Installs the `element-theme` command-line interface globally using npm, enabling access to theme generation and compilation tools from any directory. ```npm npm i element-theme -g ``` -------------------------------- ### Example API Service Folder Structure Source: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/server Illustrates the recommended directory structure for organizing API service files within the src/api folder, typically split by model or feature. ```text api/ login.js article.js remoteSearch.js ... ``` -------------------------------- ### Install Husky for Git Hooks Source: https://panjiachen.github.io/vue-element-admin-site/guide/advanced/git-hook Installs the `husky` npm package as a development dependency. Husky allows developers to easily configure Git hooks, such as `pre-commit`, to automate tasks before code is committed. ```Shell npm install husky -D -S ``` -------------------------------- ### Example Columns Configuration for Tree-Table Source: https://panjiachen.github.io/vue-element-admin-site/feature/component/tree-table Provides a JavaScript array example for the `columns` prop, detailing properties like `label`, `key`, `checkbox`, `expand`, `width`, and `alignment` for table columns. ```JavaScript const columns = [ { label: 'Checkbox', checkbox: true }, { label: '', key: 'id', expand: true }, { label: 'Event', key: 'event', width: 200, align: 'left' }, { label: 'Scope', key: 'scope' } ] ``` -------------------------------- ### Install project dependencies with npm Source: https://panjiachen.github.io/vue-element-admin-site/guide/advanced/theme Executes `npm install` within the project directory to set up all required local dependencies for the theme customization project. ```npm npm install ``` -------------------------------- ### Upgrade Node Sass to Dart Sass via npm Source: https://panjiachen.github.io/vue-element-admin-site/guide/advanced/sass This snippet provides the two essential npm commands to transition from `node-sass` to `dart-sass`. It involves uninstalling the old package and installing the new `sass` package as a development dependency, streamlining the migration process. ```Shell npm uninstall node-sass npm install sass -S -D ``` -------------------------------- ### Vue Router Example Configuration for Permission Route Source: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav An example of a Vue Router configuration for a permission-controlled route, demonstrating the use of `path`, `component`, `redirect`, `hidden`, `alwaysShow`, and `meta` properties, including nested children routes and role-based access control. ```JavaScript { path: '/permission', component: Layout, redirect: '/permission/index', hidden: true, alwaysShow: true, meta: { roles: ['admin','editor'] }, // you can set roles in root nav children: [{ path: 'index', component: _import('permission/index'), name: 'permission', meta: { title: 'permission', icon: 'lock', roles: ['admin','editor'], // or you can only set roles in sub nav noCache: true } }] } ``` -------------------------------- ### Install project dependencies Source: https://panjiachen.github.io/vue-element-admin-site/es/guide/advanced/theme Navigate into the project directory (e.g., `custom-element-theme`) and install its required Node.js dependencies using npm. ```Shell npm install ``` -------------------------------- ### Upgrade Node Sass to Dart Sass using npm Source: https://panjiachen.github.io/vue-element-admin-site/es/guide/advanced/sass This snippet provides the npm commands to uninstall 'node-sass' and install 'sass' (Dart Sass) as a development dependency, simplifying the project's build process and aligning with modern Sass practices. ```bash npm uninstall node-sass npm install sass -S -D ``` -------------------------------- ### Example Git commit to trigger pre-commit hook Source: https://panjiachen.github.io/vue-element-admin-site/es/guide/advanced/git-hook A standard Git commit command used to demonstrate how the configured pre-commit hook (via husky) will be triggered and enforce linting rules before the commit is completed. ```bash git commit -m "Keep calm and commit" ``` -------------------------------- ### Example: Export Data to Excel with Specific Headers Source: https://panjiachen.github.io/vue-element-admin-site/feature/component/excel This JavaScript example demonstrates a complete usage of 'export_json_to_excel', showing how to define custom headers and pass existing data (e.g., 'this.list') for export. It provides a practical illustration of the export process. ```javascript import('@/vendor/Export2Excel').then(excel => { const tHeader = ['Id', 'Title', 'Author', 'Readings', 'Date'] const data = this.list excel.export_json_to_excel({ header: tHeader, //Header Required data, //Specific data Required filename: 'excel-list', //Optional autoWidth: true, //Optional bookType: 'xlsx' //Optional }) }) ``` -------------------------------- ### Example Git commit triggering pre-commit hook Source: https://panjiachen.github.io/vue-element-admin-site/guide/advanced/git-hook A standard Git commit command. When executed, this command will trigger any configured `pre-commit` hooks, such as the ESLint check defined using Husky. ```Shell git commit -m "Keep calm and commit" ``` -------------------------------- ### Build Vue.js Application for Production and Stage Source: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/deploy Execute npm scripts to compile the Vue.js application for production and staging environments. This process generates a `dist` folder containing all static assets like JavaScript, CSS, and HTML files. ```bash npm run build:prod npm run build:stage ``` -------------------------------- ### Install lint-staged for selective linting Source: https://panjiachen.github.io/vue-element-admin-site/guide/advanced/git-hook Installs the `lint-staged` npm package as a development dependency. `lint-staged` is used in conjunction with Git hooks to run linters only on files that are currently staged for commit, improving performance. ```Shell npm install lint-staged -D -S ``` -------------------------------- ### Install element-theme globally Source: https://panjiachen.github.io/vue-element-admin-site/es/guide/advanced/theme Install the `element-theme` command-line tool globally using npm. This tool is essential for generating and compiling theme variables. ```Shell npm i element-theme -g ``` -------------------------------- ### Vue Component File Naming Convention (PascalCase) Source: https://panjiachen.github.io/vue-element-admin-site/guide/advanced/style-guide Demonstrates the recommended PascalCase naming convention for Vue component files, with the exception of index.vue. This convention helps distinguish components from other file types. ```File Path @/components/BackToTop/index.vue @/components/Charts/Line.vue @/views/example/components/Button.vue ``` -------------------------------- ### Install vue-count-to dependency using npm Source: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/import This command installs the `vue-count-to` package from npm and saves it as a dependency in the project's `package.json` file. ```bash $ npm install vue-count-to --save ``` -------------------------------- ### Analyze Vue.js Build File Size with Webpack Bundle Analyzer Source: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/deploy Run a command to generate a report on the size distribution of modules within your Vue.js build. This uses `webpack-bundle-analyzer` to help identify large dependencies and optimize application size. ```bash npm run preview -- --report ``` -------------------------------- ### Install Dependencies for Excel Export/Import Source: https://panjiachen.github.io/vue-element-admin-site/feature/component/excel This snippet shows the npm commands required to install the necessary packages ('xlsx', 'file-saver', 'script-loader') for Excel export and import functionalities. 'js-xlsx' is a core dependency, while 'file-saver' handles file saving and 'script-loader' assists with lazy loading. ```bash npm install xlsx file-saver -S npm install script-loader -S -D ``` -------------------------------- ### Vue View File Naming Convention (kebab-case) Source: https://panjiachen.github.io/vue-element-admin-site/guide/advanced/style-guide Shows the kebab-case naming convention for .vue files and folders under the views directory. This aligns with route URLs and helps distinguish view files from standard components. ```File Path @/views/svg-icons/index.vue @/views/svg-icons/require-icons.js ``` -------------------------------- ### Sass /deep/ to ::v-deep Syntax Migration Source: https://panjiachen.github.io/vue-element-admin-site/guide/advanced/sass This code example illustrates the necessary syntax change for scoped styles in Sass when migrating to Dart Sass. It shows how to replace the deprecated `/deep/` combinator with the `::v-deep` combinator, which is compatible with Vue's scoped CSS and aligns with future Vue specifications. ```Sass .a { /deep/ { .b { color: red; } } } /* change into */ .a { ::v-deep { .b { color: red; } } } ``` -------------------------------- ### Declare API Function for Fetching Roles Source: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/mock-api This JavaScript snippet shows the declaration of the `getRoles` API function, which uses the `request` utility to make a GET request to the `/roles` endpoint. This API is used as an example to demonstrate how to remove its corresponding mock configuration. ```JavaScript export function getRoles() { return request({ url: '/roles', method: 'get' }) } ``` -------------------------------- ### Vue Element Admin Global Styles Directory Structure Source: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/style Outlines the standard directory structure for global styles within a Vue Element Admin project, detailing common SCSS files used for buttons, Element-UI overrides, general styles, mixins, sidebar, transitions, and variables. ```text ├── styles │ ├── btn.scss # button css │ ├── element-ui.scss # global custom element-ui style │ ├── index.scss # global common style │ ├── mixin.scss # global sass mixin │ ├── sidebar.scss # sidebar css │ ├── transition.scss # vue transition animation │ └── variables.scss # global variables ``` -------------------------------- ### Mock Data Configuration for Get Roles API Source: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/mock-api This JavaScript object literal represents the mock configuration for the `getRoles` API, specifying its URL, HTTP method, and a response function that returns mock role data. This snippet is provided as an example of a mock route that would be removed to switch to real backend data. ```JavaScript { url: '/roles', type: 'get', response: _ => { return { code: 20000, data: roles } } } ``` -------------------------------- ### Example Data Structure for Tree-Table Component Source: https://panjiachen.github.io/vue-element-admin-site/feature/component/tree-table Defines the expected JavaScript array structure for the `data` prop, demonstrating how to represent hierarchical relationships using a `children` array. ```JavaScript const data = [ { name: "1", children: [ { name: "1-1" }, { name: "1-2" } ] }, { name: "2" } ] ``` -------------------------------- ### Generate new Vue component/view using plop Source: https://panjiachen.github.io/vue-element-admin-site/feature/script/new Executes the plop-based template generator to create new Vue components or views. This command automates the setup of basic file structures like