e-icon-picker 从踩坑到解决

在vue-element-admin项目中使用e-icon-picker组件时遇到渲染异常,表现为选择框空白无反应。尝试过更换e-icon-picker版本至1.1.6,升级element-ui和vue到最新版本,但问题依旧存在。在升级vue至2.7.0后出现parseComponentofundefined的错误,可能因vue-template-compiler版本不匹配导致。

在 vue-element-admin 上使用了 e-icon-picker ,但是一直渲染不出来,也没有任何报错

1.安装

npm install e-icon-picker -S

2.全局引入

// main.js
import eIconPicker from "e-icon-picker";
import "e-icon-picker/lib/symbol.js"; // 基本彩色图标库
import "e-icon-picker/lib/index.css"; // 基本样式,包含基本图标
import "font-awesome/css/font-awesome.min.css"; // font-awesome 图标库
import "element-ui/lib/theme-chalk/icon.css"; // element-ui 图标库

Vue.use(eIconPicker, {
    FontAwesome: true,
    ElementUI: true,
    eIcon: true, // 自带的图标,来自阿里妈妈
    eIconSymbol: true, // 是否开启彩色图标
    addIconList: [],
    removeIconList: [],
    zIndex: 99999// 选择器弹层的最低层,全局配置
})

3.使用

<e-icon-picker v-model="form.icon">
  <template #prepend="{ icon }">
    <e-icon :icon-name="icon" class="e-icon" />
  </template>
  <template #icon="{ icon }">
    <e-icon :icon-name="icon" class="e-icon" />
  </template>
</e-icon-picker>

跑完之后应该出现选择框的位置一片空白,点击没有任何反应

4.网上查到1.1.7这个版本可能有问题,将 1.1.7版本替换为1.1.6

"e-icon-picker": "1.1.6",

跑完并没有解决问题,还是一片空白

5.升级 element-ui 的版本

"element-ui": "2.15.7",

无效

6.升级 vue 的版本
官方文档提到,图标列表不显示是vue的一个bug,在vue-element-admin中发现,这个问题的主要原因是vue的2.6.13以前的版本和2.6.13以及2.6.14版本之间的问题,vue也没给出解决的办法,既然只出现在这些版本,那就避免用这些版本

"vue": "2.7.0",

重跑报错

Cannot read property ‘parseComponent‘ of undefined

7.升级 vue-template-compiler
vue 与 vue-template-compiler 的版本号需要一致

"vue-template-compiler": "2.7.0"

e-icon-picker

<template> <view class="container"> <view class="content"> <u-form :model="form" ref="form" :rules="rules" label-width="150"> <!-- 购课来源(选择器形式) --> <u-form-item label="购课来源" prop="sourceId" required> <view class="custom-select" @click="showSourcePicker = true"> <text class="select-text" :class="{placeholder: !form.sourceLabel}"> {{ form.sourceLabel || '请选择购课来源' }} </text> <u-icon name="arrow-down" color="#999" size="28"></u-icon> </view> <u-picker :show="showSourcePicker" :columns="[sourceOptions]" keyName="sourceName" @confirm="onSourceConfirm" @cancel="showSourcePicker = false;"> </u-picker> </u-form-item> <!-- 套餐选择 --> <u-form-item v-if="packageOptions.length > 0" label="课程套餐" prop="courseMenuId" required> <view class="package-list"> <view class="package-item" v-for="item in packageOptions" :key="item.id" :class="{'package-item-active': form.courseMenuId === item.id}" @click="form.courseMenuId = item.id"> <view class="package-name">{{item.name}}</view> <view class="package-price">¥{{item.money}}</view> <view class="package-count">私教:{{item.personaltainerTimes}}节</view> <view class="package-count">小班:{{item.publicTimes}}节</view> <view class="package-count">有效天数:{{item.publicTimes}}</view> <u-icon v-if="form.courseMenuId === item.id" name="checkbox-mark" color="#7FB8A1" size="24" class="package-check"></u-icon> </view> </view> </u-form-item> <!-- 定金开关 --> <u-form-item label="定金订单" prop="isEarnest"> <u-switch v-model="form.isEarnest" activeValue="1" inactiveValue="0" active-color="#7FB8A1"></u-switch> </u-form-item> </u-form> <!-- 提交按钮 --> <view class="submit-btn"> <u-button type="primary" shape="circle" @click="submitForm" :custom-style="buttonStyle"> 提交 </u-button> </view> </view> </view> </template> <script> import { buySourceInfo, courseMenuInfoDic, sale } from "@/api/purchase-course.js" export default { data() { return { navbarBackground: { backgroundColor: '#7FB8A1' }, buttonStyle: { backgroundColor: '#7FB8A1', color: '#FFFFFF', border: 'none' }, showSourcePicker: false, form: { sourceId: '', sourceLabel: '', courseMenuId: '', isEarnest: false, qrCode: '' }, sourceOptions: [], packageOptions: [], rules: { sourceId: [{ required: true, message: '请选择购课来源', trigger: 'change' }], courseMenuId: [{ required: true, message: '请选择课程套餐', trigger: 'change' }] } }; }, onLoad(option) { console.log(option); this.form.qrCode = option.result }, onReady() { // this.$refs.uForm.setRules(this.rules); }, mounted() { this.getBuySourceInfo() }, methods: { // 获取购课来源 getBuySourceInfo() { buySourceInfo().then((res) => { if (res.code == 200) { this.sourceOptions = res.data } }) }, // 选择购课来源 onSourceConfirm(e) { console.log(e); this.form.sourceId = e.value[0].id this.form.sourceLabel = e.value[0].sourceName this.getCourseMenuInfoDic(this.form.sourceId) this.showSourcePicker = false; }, // 获取课程套餐 getCourseMenuInfoDic(sourceId) { courseMenuInfoDic(sourceId).then((res) => { if (res.code == 200) { this.packageOptions = res.data } }) }, // 提交售课 submitForm() { console.log('开始提交表单'); this.$refs.form.validate(valid => { if (valid) { const { sourceLabel, ...buyRecordAdd } = this.form sale(buyRecordAdd).then((res) => { if (res.code == 200) { setTimeout(() => { uni.showToast({ title: '提交成功', icon: 'success' }); console.log('表单数据:', buyRecordAdd); }, 1500); } }) } else { uni.showToast({ title: '请填写完整信息', icon: 'none' }); } }) } } }; </script> <style lang="scss" scoped> .container { background-color: #f8f8f8; min-height: 100vh; } .content { padding: 20rpx 30rpx; } .custom-select { display: flex; align-items: center; justify-content: space-between; padding: 20rpx 24rpx; background-color: #fff; border: 1px solid #eee; border-radius: 8rpx; .select-text { font-size: 28rpx; color: #333; &.placeholder { color: #999; } } } .package-list { display: flex; flex-wrap: wrap; margin: -10rpx; } .package-item { width: 100%; margin: 10rpx; padding: 20rpx; background-color: #fff; border-radius: 12rpx; position: relative; border: 1px solid #eee; &-active { border-color: #7FB8A1; background-color: rgba(127, 184, 161, 0.05); } } .package-name { font-size: 28rpx; font-weight: bold; margin-bottom: 10rpx; color: #333; } .package-price { font-size: 32rpx; color: #7FB8A1; font-weight: bold; margin-bottom: 5rpx; } .package-count { font-size: 24rpx; color: #999; } .package-check { position: absolute; right: 10rpx; top: 10rpx; } .submit-btn { margin: 40rpx 0; } </style>点击submitForm没反应
07-24
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值