今天在h5上使用uniapp开发时使用robin-editor(https://ext.dcloud.net.cn/plugin?id=1345),设置字体颜色和背景颜色报错
报错如下:
[system]TypeError: Cannot read property 'open' of undefined
at VueComponent.eval (webpack-internal:///vK4t:264:28)
at Array.<anonymous> (http://localhost:8080/static/js/chunk-vendors.js:7100:12)
at flushCallbacks (http://localhost:8080/static/js/chunk-vendors.js:7026:14)
at <anonymous>
明显是调用不到那个方法,评论中有人回复
照做没有效果,看了源码,发现116行
<uni-popup type="bottom"><robin-color-picker :color="color" @confirm="colorChanged" ref="color"></robin-color-picker></uni-popup>
由于先加载popup,再加载robin-color-picker,所以直接this.$refs.color是没有值的。
将其改成
<uni-popup type="bottom" ref="popup"><robin-color-picker :color="color" @confirm="colorChanged" ref="color"></robin-color-picker></uni-popup>
再将原261行删除
this.$refs.color.open(color);
修改为
this.$refs.popup.open('bottom');
this.$nextTick(()=>{
this.$refs.color.open(color);
})
完美解决。