vue中全局引入和局部引入的实现方式是什么
Admin 2022-08-06 群英技术资讯 1298 次浏览
这篇文章给大家介绍了“vue中全局引入和局部引入的实现方式是什么”的相关知识,讲解详细,步骤过程清晰,有一定的借鉴学习价值,因此分享给大家做个参考,感兴趣的朋友接下来一起跟随小编看看吧。npm install element-plus
引入element-plus的方式是全局引入,代表的含义是所有的组件和插件都会被自动注册,
优点:上手快
缺点:会增大包的体积
在main.ts文件中
import { createApp } from 'vue'
// 全局引入
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import App from './App.vue'
import router from './router'
import store from './store'
const app = createApp(App)
app.use(router)
app.use(store)
app.use(ElementPlus)
app.mount('#app')
局部引入也就是在开发中用到某个组件对某个组件进行引入,
<template>
<div class="app">
<el-button>Default</el-button>
<el-button type="primary">Primary</el-button>
<el-button type="success">Success</el-button>
<el-button type="info">Info</el-button>
<el-button type="warning">Warning</el-button>
<el-button type="danger">Danger</el-button>
<el-button>中文</el-button>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue'
// 局部引入
import { ElButton } from 'element-plus'
import 'element-plus/theme-chalk/el-button.css'
import 'element-plus/theme-chalk/base.css'
export default defineComponent({
components: { ElButton },
setup() {
return {}
}
})
</script>
<style lang="less"></style>
但是这样我们在开发时每次使用都要手动在组件中引入对应的css样式,使用起来会比较麻烦
需要安装unplugin-vue-components 和 unplugin-auto-import这两款插件
npm install -D unplugin-vue-components unplugin-auto-import
安装完成之后在vue.config.js文件中配置
// vue.config.js
const AutoImport = require('unplugin-auto-import/webpack')
const Components = require('unplugin-vue-components/webpack')
const { ElementPlusResolver } = require('unplugin-vue-components/resolvers')
module.exports = {
outputDir: './build',
// 和webpapck属性完全一致,最后会进行合并
configureWebpack: {
resolve: {
alias: {
components: '@/components'
}
},
//配置webpack自动按需引入element-plus,
plugins: [
AutoImport({
resolvers: [ElementPlusResolver()]
}),
Components({
resolvers: [ElementPlusResolver()]
})
]
}
}
按需自动引入配置完之后,在组件中可直接使用,不需要引用和注册 这里已经实现了按需自动移入Element-plus组件 组件中直接使用:
<template>
<div class="app">
<el-button>Default</el-button>
<el-button type="primary">Primary</el-button>
<el-button type="success">Success</el-button>
<el-button type="info">Info</el-button>
<el-button type="warning">Warning</el-button>
<el-button type="danger">Danger</el-button>
<el-button>中文</el-button>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue'
export default defineComponent({
setup() {
return {}
}
})
</script>
<style lang="less"></style>
效果:

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
接到需求需要一个服务来执行shell脚本,要求可以实时打印shell脚本执行的过程,并看到脚本执行的结果。明确任务目标:这是一个web服务,需要执行shell脚本当一个脚本执行的时候,再次发送请求需要等待当前脚本执行完毕,再自动执行这次请求使用长连接而不是socket添加脚本不需要重启服务器这里采用的是express框架开始首先搭好express基本框架新建
本文实例为大家分享了VUE递归树形实现多级列表,供大家参考,具体内容如下什么是递归?简单来说就是在组件中内使用组件本身。为什么要用递归?如果出现很多下拉菜单,同级,分级数据,层级混杂,可以使用v-for的嵌套循环不就完事了。对,没毛病这样的话也可以做,但是如果数据又多加了【很多】级分类呢;使用v-for也能实现,但是代
这篇文章我们来了解jQuery怎样删除子元素的相关内容,在删除子元素之前,首先我们需要先获取子元素,这里需要使用children()方法来获取子元素对象,然后再用remove()方法就能删除子元素了,文中的示例代码介绍得很详细,有需要的朋友可以参考,接下来就跟随小编一起了解看看吧。
这篇文章给大家分享的是JS中getday方法的相关内容。在javascript中,escape()方法能用于指定日期是星期几,小编觉得挺实用的,因此分享给大家做个参考,文中的示例代码介绍得很详细,有需要的朋友可以参考,接下来就跟随小编一起学习一下吧。
本文实例为大家分享了JS旋转实现转盘抽奖效果的具体代码,供大家参考,具体内容如下闲来没事,做了一个模拟转盘抽奖的HTML&JS的效果:可以在设置的时候,选择几个区域,并且可以填写指针将要停止的区域
成为群英会员,开启智能安全云计算之旅
立即注册Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008