描述
做一个ts+vue+element-plus项目的时候总是有警告
消除警告
- 将
src/plugins/element.js
文件后缀名改成ts- 在element里面还要对脚手架现有的代码进行类型限制
在element.ts中引入
import { App } from 'vue'
在element.ts中 对参数app和函数返回值进行类型限制
export default (app:App<Element>):void => {
locale.use(lang)
components.forEach(component => {
app.use(component)
})
// app.use(ElButton).use(ElFormItem).use(ElForm).use(ElInput).use(ElLink).use(ElMain).use(ElMenu).use(ElHeader).use(ElContainer).use(ElAside)
}
修改后的element.ts文件
import {
ElButton,
ElForm,
ElFormItem,
ElInput,
ElLink,
ElContainer,
ElHeader,
ElAside,
ElMain,
ElMenu,
ElMenuItem,
ElMenuItemGroup,
ElSubmenu,
ElRow,
ElCol,
ElAlert
} from 'element-plus'
import lang from 'element-plus/lib/locale/lang/zh-cn'
import locale from 'element-plus/lib/locale'
import { App } from 'vue'
const components = [
ElButton,
ElForm,
ElFormItem,
ElInput,
ElLink,
ElContainer,
ElHeader,
ElAside,
ElMain,
ElMenu,
ElMenuItem,
ElMenuItemGroup,
ElSubmenu,
ElRow,
ElCol,
ElAlert
]
export default (app:App<Element>):void => {
locale.use(lang)
components.forEach(component => {
app.use(component)
})
// app.use(ElButton).use(ElFormItem).use(ElForm).use(ElInput).use(ElLink).use(ElMain).use(ElMenu).use(ElHeader).use(ElContainer).use(ElAside)
}