オンデマンドで導入される要素 UI

1. npm インストール [グローバル インストール要素]   

npm i element-ui -S

2. babel-plugin-componentを使用して、オンデマンドでインポートします  

        2.1、最初に babel-plugin-componentをインストールします。

npm install babel-plugin-component -D

        2.2. .babelrc を次のように変更します: [プロジェクト内の babel.config.js ファイルです]

{
  "presets": [["es2015", { "modules": false }]],
  "plugins": [
    [
      "component",
      {
        "libraryName": "element-ui",
        "styleLibraryName": "theme-chalk"
      }
    ]
  ]
}

        2.3. main.js に必要なコンポーネントを導入する

例: ボタン、選択

//引入需要的组件
import { Button, Select } from 'element-ui';

//使用组件
Vue.component(Button.name, Button);
Vue.component(Select.name, Select);

        2.4、またはプロトタイプに取り付けて使用


//引入组件
import {MessageBox } from 'element-ui';

//挂载到原型上使用
Vue.prototype.$msgbox = MessageBox;
Vue.prototype.$alert = MessageBox.alert;

注: 依存関係をダウンロードできない場合は、コマンドの各行の後に追加してください。  

--legacy-peer-deps

おすすめ

転載: blog.csdn.net/m0_69644606/article/details/127881014