自定义组件报错,
VM79506:2 webviewScriptError
Cannot read property 'replace' of undefined;[Exparser] [Error] [Component] Lifetime Method Error @ wx-cover-view#attached
TypeError: Cannot read property 'replace' of undefined
at o.attached (http://127.0.0.1:64847/__pageframe__/__dev__/WAWebview.js:8:5912)
at r.safeCallback (http://127.0.0.1:64847/__pageframe__/__dev__/WAWebview.js:5:27178)
at r.call (http://127.0.0.1:64847/__pageframe__/__dev__/WAWebview.js:5:26942)
at t (http://127.0.0.1:64847/__pageframe__/__dev__/WAWebview.js:6:7737)
at t (http://127.0.0.1:64847/__pageframe__/__dev__/WAWebview.js:6:8050)
at t (http://127.0.0.1:64847/__pageframe__/__dev__/WAWebview.js:6:7992)
at t (http://127.0.0.1:64847/__pageframe__/__dev__/WAWebview.js:6:8050)
at t (http://127.0.0.1:64847/__pageframe__/__dev__/WAWebview.js:6:8050)
at t (http://127.0.0.1:64847/__pageframe__/__dev__/WAWebview.js:6:8050)
at t (http://127.0.0.1:64847/__pageframe__/__dev__/WAWebview.js:6:8050)
(anonymous) @ VM79506:2
VM79507:2 [Exparser] [Error] [Component] Lifetime Method Error @ wx-cover-view#attached
(anonymous) @ VM79507:2
VM79508:2 TypeError: Cannot read property 'replace' of undefined
at o.attached (:64847/__pageframe__/__dev__/WAWebview.js:8)
at r.safeCallback (:64847/__pageframe__/__dev__/WAWebview.js:5)
at r.call (:64847/__pageframe__/__dev__/WAWebview.js:5)
at t (:64847/__pageframe__/__dev__/WAWebview.js:6)
at t (:64847/__pageframe__/__dev__/WAWebview.js:6)
at t (:64847/__pageframe__/__dev__/WAWebview.js:6)
at t (:64847/__pageframe__/__dev__/WAWebview.js:6)
at t (:64847/__pageframe__/__dev__/WAWebview.js:6)
at t (:64847/__pageframe__/__dev__/WAWebview.js:6)
at t (:64847/__pageframe__/__dev__/WAWebview.js:6)
(anonymous) @ VM79508:2
组件如下:
js:
Component({
properties: {
top: {
type: Number,
value: 0
},
left: {
type: Number,
value: 0
},
iconSrc: {
type: String,
value: ''
},
animation: {
type: Object,
value: {}
}
}
});
wxml:
<cover-view class="indicator" style="top:{{top}}rpx; left:{{left}}rpx;" animation="{{animation}}">
<cover-view class="indicator-tip">
<cover-image class="indicator-icon" src="{{iconSrc}}"></cover-image>
<!--a-->
<slot></slot>
</cover-view>
</cover-view>
wxss:
.indicator{
opacity: 0.6;
z-index: 999;
color: white;
font-size: 26rpx;
position: absolute;
background-color: #565A5C;
}
.indicator-tip{
margin: 24rpx 42rpx;
display: flex;
justify-content: space-around;
}
.indicator-icon{
width: 36rpx;
height: 36rpx;
margin-right: 10rpx;
}
json:
{
"component": true
}
组件使用:
json:
{
"disableScroll": true,
"usingComponents": {
"mapindicator": "/pages/components/mapindicator/mapindicator"
}
}
wxml:
<mapindicator top="800" left="" iconSrc="/static/images/clear/clear-all.png">xxxxxxxxxxxxxx</mapindicator>
引入页html
<view
class
=
"paying"
bindtap=
'goplay'
data-index=
"{{index}}"
>
<span>付款</span>
<time-compent inner-text=
"{{itemName.order.leftTime}}"
></time-compent>
</view>
自定义组件JS
Component({
properties: {
innerText: {
type:
null
,
value:
''
}
},
data: {
durTime:
''
,
},
attached:
function
() {
var
that =
this
that.setData({
durTime:
parseInt
(that.properties.innerText /
1000
)
})
}
})
自定义组件html
<view
class
=
"inner"
>
{{durTime}}
</view>
我的意思是自定义组件的Component下的properties只是负责把外部的值引入到组件内来,你内部想要使用外部引入的值,需要把properties内的值赋值给Component下的data,组件内部没法直接使用properties下的值,而你在组件内部居然能直接使用properties下的值不经过赋值给data,而且父页面赋值的变量名直接就是properties下的iconSrc,至少去年我写自定义组件时,iconSrc是不能直接引用的,必须是icon-Src,而且内部使用必须转换为data,好吧,我刚刚按照你的方式没转化data,属性名也直接使用,对外显示正常的,这点我昨天没主动测试,还抱着去年的思维,很是抱歉。不过如果你还想利用这个值在组件内部做进行其他赋值或者转化操作,还时需要赋值给内部data,这点还是没变化,再次为昨天的没有主动测试表示抱歉
腾讯的大神们好好处理一下cover-系列的组件吧,太难用了
怎么没有意义,你能说img标签的src属性没有意义吗?
各位,我试过了,是cover-view的问题,把cover-view换成view,cover-image开始报错,再把cover-image换成image,不报错了
mapindicator 这个标签内部显示的内容就是 你这个插件先不说写法对不对,存在完全没意义啊,资源都是固定的clear-all.png
你自定义组件的内部iconSrc需要写到插件的data里,properties里面的字段是对外引用字段
有时开发工具会有bug,重新编译即可,不知道你是不是这种情况