vue3使用element?ui的方法實例
前言
element-ui支持vue2版本,當(dāng)用vue3安裝element-ui的時候會報錯,這就需要安裝element-plus版本來用到vue3項目中。
element-ui網(wǎng)址:https://element.eleme.cn/#/zh-CN/
element-plus網(wǎng)址:https://element-plus.gitee.io/zh-CN/
1、首先安裝element-plus
npm install element-plus --save
可以在package.json中檢查是否安裝成功
出現(xiàn)這一行就證明安裝成功了...
2、修改main.js或main.ts文件
import { createApp } from "vue"; import App from "./App.vue"; import router from "./router"; import store from "./store"; import ElementPlus from 'element-plus'; import 'element-plus/theme-chalk/index.css'; import locale from 'element-plus/lib/locale/lang/zh-cn' createApp(App).use(store).use(router).use(scroll).use(ElementPlus, { locale }).mount("#app");
3、然后在代碼中使用
<template> <div class="Select"> <el-select v-model="value" filterable placeholder="請選擇"> <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" /> </el-select> </div> </template>
<script lang="ts"> import { defineComponent, ref } from "vue"; export default defineComponent({ name: "Select", props: {}, setup() { const value = ref(""); const options = [ { value: "上海市", label: "上海市", }, { value: "杭州市", label: "杭州市", }, { value: "北京市", label: "北京市", }, { value: "天津市", label: "天津市", }, { value: "重慶市", label: "重慶市", }, ]; return { value, options, }; }, }); </script>
然后應(yīng)該就可以了...
4、有的會出現(xiàn)報錯,那就再安裝一下element ui
npm install element-ui -S
補充:新引入Element Plus
npm install element-plus --save
main.js中引入
import { createApp } from 'vue' import App from './App.vue' import router from './router' import store from './store' // import '@/assets/scss/reset.scss' import ElementUI from 'element-plus' import 'element-plus/lib/theme-chalk/index.css' createApp(App).use(store).use(router).use(ElementUI).mount('#app')
啟動后,項目能正常顯示。
總結(jié)
到此這篇關(guān)于vue3使用element ui的文章就介紹到這了,更多相關(guān)vue3使用element ui內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vite.config.ts如何加載.env環(huán)境變量
這篇文章主要介紹了vite.config.ts加載.env環(huán)境變量方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-10-10基于Vue+ELement搭建動態(tài)樹與數(shù)據(jù)表格實現(xiàn)分頁模糊查詢實戰(zhàn)全過程
這篇文章主要給大家介紹了關(guān)于如何基于Vue+ELement搭建動態(tài)樹與數(shù)據(jù)表格實現(xiàn)分頁模糊查詢的相關(guān)資料,Vue Element UI提供了el-pagination組件來實現(xiàn)表格數(shù)據(jù)的分頁功能,需要的朋友可以參考下2023-10-10