插件
插件通常用来为 Vue 添加全局功能。插件的功能范围没有严格的限制——一般有下面几种:
- 添加全局方法或者属性。如: vue-custom-element
- 添加全局资源:指令/过滤器/过渡等。如 vue-touch
- 通过全局混入来添加一些组件选项。如 vue-router
- 添加 Vue 实例方法,通过把它们添加到
Vue.prototype
上实现。 - 一个库,提供自己的 API,同时提供上面提到的一个或多个功能。如 vue-router
示例:安装 ElementUI
安装:
yarn add element-ui
引入,在 main.js 中写入以下内容:
import Vue from 'vue'import App from './App.vue'import ElementUI from 'element-ui';import 'element-ui/lib/theme-chalk/index.css';Vue.config.productionTip = falseVue.use(ElementUI);new Vue({ render: h => h(App),}).$mount('#app')在组件中使用:
<template> <div> <Button>Button</Button> </div></template><script>import { Button } from 'element-ui';export default { components: { Button }};</script>更多配置参考 官方文档



